sendlyst / sendlyst-php
Framework-agnostic PHP SDK for pushing events and syncing contacts into a Sendlyst workspace.
Requires
- php: ^8.2
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^11.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.1|^2.0
Suggests
- psr/http-client: To send requests through your own PSR-18 HTTP client instead of the built-in cURL transport.
- psr/http-factory: Required alongside psr/http-client when using Psr18Transport.
Provides
None
Conflicts
None
Replaces
None
README
Framework-agnostic PHP SDK for Sendlyst: push events and sync contacts into a Sendlyst workspace from any PHP app (Symfony, WordPress, vanilla PHP, ...). Laravel apps should use sendlyst/laravel instead, which builds on this package.
Status (Nov 2026): speaks Sendlyst's REST API v1 (phase 1a: contacts, events, ping). Contract: apps/sendlyst/docs/data-sync/06-rest-api-and-webhooks.md. Not on Packagist or npm yet: install from this repository. Plans, subscriptions and objects come in phase 1b.
Zero runtime dependencies — a built-in cURL transport is used unless you inject your own PSR-18 client.
Install
// composer.json of the consuming app "repositories": [ { "type": "path", "url": "/path/to/sendlyst/packages/sendlyst-php", "options": { "symlink": true } } ], "require": { "sendlyst/sendlyst-php": "@dev" }
Usage
use Sendlyst\Config; use Sendlyst\SendlystClient; $sendlyst = new SendlystClient(new Config( apiKey: 'eh_live_...', // from Sendlyst: Integrations → Connect an app baseUrl: 'https://your-sendlyst-host/api/v1', // group: 'ebookwriter', // only for a key not tied to a group )); // Verify the credential (group, connection, scopes) $sendlyst->ping(); // Upsert contacts (keyed by your external_id, then email). Only keys present are // written; null clears a field. Consent can only be turned off; tags are only added. $sendlyst->contacts()->upsert([ 'external_id' => 'user-1', 'email' => 'jane@example.com', 'first_name' => 'Jane', 'attributes' => ['role' => 'admin', 'books_count' => 3], 'updated_at' => '2026-11-17T09:00:00Z', // older updates arriving late are skipped as stale ]); $result = $sendlyst->contacts()->upsertBatch($manyContacts); // chunks > 500 automatically $result->created; $result->updated; $result->unchanged; $result->stale; $result->rejectedItems(); // Track events. event_id is auto-generated before the first attempt, so retries are idempotent. // Send the email too when the user may not be synced yet: Sendlyst then creates the contact. $sendlyst->events()->track('book_published', externalId: 'user-1', properties: ['book_id' => 8841]); $sendlyst->events()->trackBatch([ ['name' => 'page_viewed', 'external_id' => 'user-1', 'properties' => ['path' => '/pricing']], ]); // Read back (status, consent, attributes) and delete $sendlyst->contacts()->get('user-1'); // array, or null when Sendlyst does not know them $sendlyst->contacts()->delete('user-1'); // they leave the group; false when unknown
Buffering many events in one process:
$buffer = new \Sendlyst\Buffer\EventBuffer($sendlyst->events()); $buffer->add(['name' => 'step_completed', 'external_id' => 'user-1']); $buffer->flush(); // auto-flushes at 500 too
Declaring meters (things people use up, from contact attributes you send; skip if your app has none):
$sendlyst->describe(['meters' => [ ['used' => 'credits_used', 'limit' => 'credits', 'label' => 'Credits'], ['used' => 'exports'], // no cap ]]);
Verifying Sendlyst webhooks
Sendlyst signs every outbound webhook with EngageHub-Signature: t=<unix>,v1=<hex>,
where v1 = HMAC-SHA256(secret, "<t>.<raw body>"). Verify against the raw body
and reject stale timestamps (default tolerance 300 s):
use Sendlyst\Webhooks\WebhookSignature; use Sendlyst\Exceptions\SignatureVerificationException; try { $event = WebhookSignature::constructEvent( file_get_contents('php://input'), $_SERVER['HTTP_ENGAGEHUB_SIGNATURE'] ?? '', getenv('SENDLYST_WEBHOOK_SECRET'), ); } catch (SignatureVerificationException) { http_response_code(400); exit; }
Errors & retries
429 / 5xx / network failures retry automatically (exponential backoff + jitter, honors Retry-After). After retries, calls throw typed exceptions: AuthenticationException (401), AuthorizationException (403), NotFoundException (404), ValidationException (422, ->errors()), RateLimitException (429, ->retryAfter()), ServerException (5xx), NetworkException. Per-item rejections (invalid, identity_conflict, email_taken, unknown_contact) return in the result DTOs instead of throwing. A paused connection answers 423 (SendlystException).
Inject your own HTTP stack:
$sendlyst = new SendlystClient($config, new \Sendlyst\Http\Psr18Transport($psr18Client, $requestFactory, $streamFactory));
Tests
composer install && composer test