Java SDK
Zero-dependency Java SDK for the Synapse API. Published as tech.pyrx:synapse on Maven Central. Uses only java.net.http.HttpClient (no external dependencies).
Requires Java 11+.
Installation
Maven
Gradle
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 |
timeoutSeconds | 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_*), available via client.getEnvironment().
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. Network errors (ConnectException, HttpTimeoutException) are also retried. Client errors (400, 401, 403, 404, 422) are never retried.
AutoCloseable: SynapseClient implements AutoCloseable, so you can use it with try-with-resources.
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 | Map | No | Arbitrary key-value event data |
contact | Map | 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 on the Webhooks class -- 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)
You can pass true as the fourth argument to Webhooks.verify() to disable the timestamp check (useful for testing only).
Error Handling
The SDK provides typed exception classes for every failure mode. All errors extend SynapseError (an unchecked RuntimeException).
Error Types
| Error Class | HTTP Status | Fields | When |
|---|---|---|---|
SynapseError | Any | getStatus(), getMessage(), getCode(), getRequestId() | Base type for all API errors |
SynapseAuthError | 401, 403 | getMessage() | Invalid or expired API key, scope mismatch |
SynapseValidationError | 422 | getErrors() with getField() + getMessage() | Request body validation failed |
SynapseRateLimitError | 429 | getRetryAfter() (seconds) | Rate limit exceeded (auto-retried) |
SynapsePlanLimitError | 403 | getLimitType(), getCurrent(), getMaximum(), getPlan() | Plan limit reached |
Environment Variables
For production deployments, load credentials from environment variables.
Full Method Reference
| Method | Description | Required Scope |
|---|---|---|
client.track(params) | Track a single event | data |
client.trackBatch(params) | Track up to 50 events | data |
client.identify(params) | Upsert a single contact | data |
client.identifyBatch(params) | Upsert up to 1,000 contacts | data |
client.send(params) | Send a transactional email | data |
client.contacts.list(params) | List contacts with pagination | management |
client.contacts.get(id) | Get a single contact | management |
client.contacts.update(id, params) | 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, params) | Preview rendered template | management |
client.templates.delete(slug) | Delete a template | management |
Webhooks.verify(payload, headers, secret) | Verify webhook signature | -- |
Framework Examples
Spring Boot
Webhook Endpoint (Spring Boot)
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
-
PHP SDK -- server-side SDK for PHP
-
Go SDK -- server-side SDK for Go
-
C#/.NET SDK -- server-side SDK for C#/.NET
-
Browser SDK -- client-side event tracking
-
Event Ingestion API -- raw REST API
-
API Reference -- interactive API explorer
-
Error Codes -- complete error code list