Skip to main content

PHP SDK

santati/santati-php is the official PHP client for the Santati audit-log API, published on Packagist. Requires PHP 8.2+ (Guzzle).

Install​

composer require santati/santati-php

Create a client​

require 'vendor/autoload.php';

use Santati\Client;

$client = new Client(apiKey: getenv('SANTATI_API_KEY'), trail: 'billing');
optiondefaultmeaning
apiKeyrequired, non-emptyteam API key (sat_sk_…)
baseUrlhttps://api.santati.ioa trailing slash is dropped; a path prefix is kept
trailnonedefault trail for emits, never applied to reads
timeoutMs10000per attempt
maxRetries2retries after the first attempt
initialBackoffMs250backoff base
maxBackoffMs8000backoff cap
headersnoneextra headers on every request

trail is the default trail for emits and is never applied to reads. Construction fails with a ValidationException for an empty key or an Authorization header in headers.

Emit an event​

$result = $client->events->emit([
'event' => 'invoice.voided',
'organization_id' => 'org_acme',
'actor' => ['type' => 'user', 'id' => 'usr_123', 'name' => 'Valentine Michael Smith'],
'targets' => [['type' => 'invoice', 'id' => 'inv_555']],
]);

printf("%s (duplicate: %s)\n", $result->event->getId(), $result->duplicate ? 'yes' : 'no');

Without an idempotency_key one is generated for you, and duplicate is true when the server replayed an earlier request. See Idempotency and Event envelope.

Emit a batch​

$batch = $client->events->emitBatch([
['event' => 'invoice.voided', 'idempotency_key' => 'void-1', 'organization_id' => 'org_acme'],
['event' => 'invoice.paid', 'organization_id' => 'org_acme'],
]);

printf("%d accepted, %d rejected\n", $batch->accepted, $batch->rejected);

A 202 and a 207 both return a result with per-item status (accepted, duplicate or rejected) in $batch->results, and the server enforces 500 events / 1 MiB — a 413 arrives as a validation error. See Batching.

List and iterate​

$page = $client->events->list(['trail' => 'billing', 'limit' => 50]);

foreach ($page->results as $event) {
printf("%s %s\n", $event->getId(), $event->getEvent());
}

foreach ($client->events->iterate(['trail' => 'billing', 'limit' => 200]) as $event) {
printf("%s %s\n", $event->getId(), $event->getEvent());
}

list() accepts trail, event, event_prefix, organization_id, actor_id, actor_type, target_type, target_id, created_after, created_before, q, sort, limit and cursor as [$name => $value]; unknown names raise a ValidationException. iterate() returns a \Generator and walks every page lazily. See Searching events.

Errors and retries​

Every failure is a Santati\Exception\SantatiException with getStatus(), getErrorCode(), getField() and getRetryAfter():

kindwhen
ValidationExceptionlocal validation (getStatus() is null), or HTTP 400, 413, 422
AuthExceptionHTTP 401, 403
NotFoundExceptionHTTP 404
RateLimitedExceptionHTTP 429
ServerExceptionHTTP 5xx
TransportExceptionno response: refused, DNS, TLS, timeout (getStatus() is null)
ApiExceptionany other status, an unexpected 2xx, or an undecodable body
use Santati\Exception\RateLimitedException;

try {
$client->events->emit(['event' => 'invoice.voided', 'organization_id' => 'org_acme']);
} catch (RateLimitedException $e) {
echo $e->getRetryAfter(); // seconds, from the Retry-After header — or null
}

An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to maxRetries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds maxBackoffMs, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.