PHP SDK
Zero-dependency PHP SDK for the Synapse API. Published as pyrx/synapse on Packagist. Uses only PHP stdlib (curl, json, openssl).
Requires PHP 8.1+.
Installation
Quick Start
Get your API key and workspace ID from the dashboard at Settings > API Keys.
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Your Synapse API key (psk_live_* or psk_test_*) |
workspaceId | string | required | Your workspace identifier |
baseUrl | string | https://synapse-api.pyrx.tech | API base URL |
timeout | int | 30 | Request timeout in seconds |
maxRetries | int | 3 | Retry count for 429/5xx errors. Set to 0 to disable. |
Environment detection: The SDK detects test or live from your API key prefix (psk_test_* vs psk_live_*).
Retry behavior: The SDK automatically retries on 429, 500, 502, 503, and 504 with exponential backoff and jitter (capped at 30s). On 429, uses the Retry-After header when present. Curl connection errors are also retried. Client errors (400, 401, 403, 404, 422) are never retried.
Track Events
Single Event
| Parameter | Type | Required | Description |
|---|---|---|---|
externalId | string | Yes | Your unique user identifier |
eventName | string | Yes | Event name (e.g., purchase_completed) |
attributes | array | No | Arbitrary key-value event data |
contact | array | No | Contact fields to upsert alongside the event |
idempotencyKey | string | No | Prevents duplicate processing (7-day TTL) |
occurredAt | string | No | ISO 8601 timestamp. Defaults to server time. |
Batch Events
Track up to 50 events in a single request.
Identify Contacts
Single Contact
Create or update (upsert) a contact by externalId.
Batch Identify
Upsert up to 1,000 contacts in a single request.
Send Transactional Email
Send a one-off email using an NLT template, without a flow.
Requires a data-scoped API key (or higher). The template must exist in your workspace.
Contact Management
The $client->contacts sub-client provides full CRUD operations. Requires a management or full scoped API key.
List Contacts
Get a Contact
Update a Contact
Delete a Contact
Template Management
The $client->templates sub-client manages email templates. Requires a management or full scoped API key.
List Templates
Get a Template
Create a Template
Update a Template
Preview with Sample Data
Delete a Template
Webhook Verification
Verify incoming webhook signatures to ensure requests are authentically from Synapse. This is a static method -- no client instance needed.
The verification checks:
- All three
svix-*headers are present - The timestamp is within 5 minutes (replay attack protection)
- The HMAC-SHA256 signature matches (supports multiple signatures for key rotation)
Error Handling
The SDK provides typed error classes for every failure mode.
Error Types
| Error Class | HTTP Status | Properties | When |
|---|---|---|---|
SynapseError | Any | status, message, code, requestId | Base class for all API errors |
SynapseAuthError | 401, 403 | message | Invalid or expired API key, scope mismatch |
SynapseValidationError | 422 | errors[] with field + message | Request body validation failed |
SynapseRateLimitError | 429 | retryAfter (seconds) | Rate limit exceeded |
SynapsePlanLimitError | 403 | limitType, current, maximum, plan | Plan limit reached |
Environment Variables
For production deployments, load credentials from environment variables.
Full Method Reference
| Method | Description | Required Scope |
|---|---|---|
$client->track(...) | Track a single event | data |
$client->trackBatch(...) | Track up to 50 events | data |
$client->identify(...) | Upsert a single contact | data |
$client->identifyBatch(...) | Upsert up to 1,000 contacts | data |
$client->sendEmail(...) | Send a transactional email | data |
$client->contacts->list(...) | List contacts with pagination | management |
$client->contacts->get($id) | Get a single contact | management |
$client->contacts->update($id, $data) | Update a contact | management |
$client->contacts->delete($id) | Delete a contact | management |
$client->templates->list() | List all templates | management |
$client->templates->get($slug) | Get a template by slug | management |
$client->templates->create($params) | Create a template | management |
$client->templates->update($slug, $params) | Update a template | management |
$client->templates->preview($slug, $data) | Preview rendered template | management |
$client->templates->delete($slug) | Delete a template | management |
Webhooks::verify($payload, $headers, $secret) | Verify webhook signature | -- |
Framework Examples
Laravel
Webhook Endpoint (Laravel)
Related Resources
-
Node.js Server SDK -- server-side SDK for Node.js
-
Python SDK -- server-side SDK for Python
-
Ruby SDK -- server-side SDK for Ruby
-
Go SDK -- server-side SDK for Go
-
Browser SDK -- client-side event tracking
-
Event Ingestion API -- raw REST API
-
API Reference -- interactive API explorer
-
Error Codes -- complete error code list