Node.js Server SDK
TypeScript-first, zero-dependency Node.js SDK for the Synapse API. Published as @pyrx/synapse on npm.
Requires Node.js 18+ (uses native fetch).
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 | number | 30000 | Request timeout in milliseconds |
maxRetries | number | 3 | Retry count for 429/5xx errors. Set to 0 to disable. |
debug | boolean | false | Log every request URL to console |
Environment detection: The SDK detects test or live from your API key prefix (psk_test_* vs psk_live_*), available via synapse.environment.
Retry behavior: The SDK automatically retries on 429, 500, 502, 503, and 504 with exponential backoff and jitter. 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 | object | No | Arbitrary key-value event data |
contact | object | 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 synapse.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 synapse.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
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 (auto-retried) |
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 |
|---|---|---|
synapse.track(params) | Track a single event | data |
synapse.trackBatch(params) | Track up to 50 events | data |
synapse.identify(params) | Upsert a single contact | data |
synapse.identifyBatch(params) | Upsert up to 1,000 contacts | data |
synapse.send(params) | Send a transactional email | data |
synapse.contacts.list(params) | List contacts with pagination | management |
synapse.contacts.get(id) | Get a single contact | management |
synapse.contacts.update(id, params) | Update a contact | management |
synapse.contacts.delete(id) | Delete a contact | management |
synapse.templates.list() | List all templates | management |
synapse.templates.get(slug) | Get a template by slug | management |
synapse.templates.create(params) | Create a template | management |
synapse.templates.update(slug, params) | Update a template | management |
synapse.templates.preview(slug, data) | Preview rendered template | management |
synapse.templates.delete(slug) | Delete a template | management |
Framework Examples
Express.js
Next.js API Route
Related Resources
-
Browser SDK -- client-side event tracking
-
Event Ingestion API -- raw REST API
-
API Reference -- interactive API explorer
-
Error Codes -- complete error code list