Go SDK
Zero-dependency Go SDK for the Synapse API. Published as github.com/pyrx-tech/pyrx-synapse-go. Uses only Go stdlib (net/http, crypto/hmac, encoding/json).
Requires Go 1.21+.
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 | time.Duration | 30s | Request timeout |
MaxRetries | int | 3 | Retry count for 429/5xx errors. Set to 0 to disable. |
NewClient returns (*Client, error) -- it validates config and returns an error if APIKey or WorkspaceID are empty. All API methods return (result, error) -- idiomatic Go error handling.
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 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 | map[string]any | No | Arbitrary key-value event data |
Contact | map[string]any | 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 package-level function -- 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)
The fourth parameter (false) controls strict mode. Set to true to reject timestamps outside the tolerance window.
Error Handling
The SDK provides typed error structs for every failure mode. Use errors.As to check error types.
Error Types
| Error Type | HTTP Status | Fields | When |
|---|---|---|---|
*synapse.SynapseError | Any | Status, Message, Code, RequestID | Base type for all API errors |
*synapse.SynapseAuthError | 401, 403 | Message | Invalid or expired API key, scope mismatch |
*synapse.SynapseValidationError | 422 | Errors[] with Field + Message | Request body validation failed |
*synapse.SynapseRateLimitError | 429 | RetryAfter (seconds) | Rate limit exceeded |
*synapse.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(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, 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 |
synapse.VerifyWebhook(payload, headers, secret, strict) | Verify webhook signature | -- |
Framework Examples
net/http
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
-
Browser SDK -- client-side event tracking
-
Event Ingestion API -- raw REST API
-
API Reference -- interactive API explorer
-
Error Codes -- complete error code list