Browse Docs

PHP Alerts SDK

The API Alerts PHP SDK sends alerts from your PHP code through API Alerts. Drop it into Laravel applications, WordPress sites, Symfony services, or any PHP script that needs to notify you when something important happens. Minimal setup, fire-and-forget by default with optional response handling, and zero infrastructure.

Installation

composer require apialerts/apialerts:1.0.0

Quick Start

use ApiAlerts\ApiAlerts;
use ApiAlerts\Event;

ApiAlerts::configure('your-api-key');
ApiAlerts::send(new Event(message: 'Deploy complete'));

Usage

Configure the singleton (ApiAlerts) once at startup, then send from anywhere. For dependency injection, mocking, or multiple keys, use the instance client instead.

Fire and forget

ApiAlerts::configure('your-api-key');

// Errors are silently swallowed. Safe to call anywhere.
ApiAlerts::send(new Event(message: 'Deploy complete'));

Wait for response

$result = ApiAlerts::sendAsync(new Event(
    message: 'New user signed up',
    channel: 'revenue',
    event:   'user.signup',
    title:   'New Signup',
    tags:    ['growth', 'organic'],
    link:    'https://dashboard.example.com/users/123',
    data:    ['plan' => 'pro', 'source' => 'organic'],
));

echo "Sent to {$result->workspace} ({$result->channel})\n";

Dependency injection

The static facade is the quickest way to send. When you use DI, mock in tests, or need multiple keys, construct the instance Client and type-hint against ApiAlertsClientInterface:

use ApiAlerts\ApiAlertsClientInterface;
use ApiAlerts\Client;

$client = new Client('your-api-key');
$client->send(new Event(message: 'Deploy complete'));

In Laravel, bind the interface in a service provider so the container injects it:

$this->app->singleton(
    ApiAlertsClientInterface::class,
    fn () => new Client(config('services.apialerts.key')),
);

class DeployNotifier
{
    public function __construct(private ApiAlertsClientInterface $alerts) {}
}

ApiAlerts is a thin facade over a default Client, so the singleton and instance client share the same behaviour.

Multiple workspaces

Pass apiKey to override the configured key for a single call:

$result = ApiAlerts::sendAsync(
    new Event(message: 'Cross-workspace event'),
    apiKey: 'other-api-key',
);

Event Fields

FieldTypeRequiredDescription
messagestringYesMain notification message
channelstringNoTarget channel name
eventstringNoEvent key for routing
titlestringNoShort title
tagsstring[]NoCategorisation tags
linkstringNoURL attached to the notification
dataarrayNoArbitrary key-value metadata