Appearance
API Overview
The Nexus API is a RESTful API that allows you to send notifications, manage subscribers, and configure your notification infrastructure programmatically.
Base URL
text
https://api.nexus.devtext
https://your-domain.com/apitext
http://localhost:3001Authentication
Nexus uses API keys for authentication. Include your API key in the Authorization header:
http
Authorization: Bearer sk_live_1234567890abcdefAPI Key Types
| Type | Format | Environment | Description |
|---|---|---|---|
| Live | sk_live_... | Production | For production use |
| Test | sk_test_... | Development | For testing and development |
WARNING
Keep your API keys secure and never expose them in client-side code. Use environment variables to store them safely.
Rate Limits
Rate limits are applied per API key and vary by plan:
| Plan | Requests per minute | Burst limit |
|---|---|---|
| Free | 100 | 200 |
| Pro | 1,000 | 2,000 |
| Enterprise | 10,000 | 20,000 |
When you exceed the rate limit, you'll receive a 429 status code:
json
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Try again in 60 seconds.",
"retryAfter": 60
}
}Request Format
Content Type
All requests must use Content-Type: application/json for POST/PUT requests.
Request Structure
json
{
"to": "subscriber-id-or-email",
"payload": {
"key": "value"
}
}Headers
http
POST /v1/events/trigger
Host: api.nexus.dev
Authorization: Bearer sk_live_1234567890abcdef
Content-Type: application/json
User-Agent: YourApp/1.0.0Response Format
Success Response
json
{
"data": {
"id": "msg_123",
"status": "sent",
"createdAt": "2024-01-15T10:30:00Z"
}
}Error Response
json
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid email address",
"details": {
"field": "email",
"value": "invalid-email"
}
}
}HTTP Status Codes
| Code | Description |
|---|---|
200 | Success |
201 | Created |
400 | Bad Request - Invalid input |
401 | Unauthorized - Invalid API key |
403 | Forbidden - Insufficient permissions |
404 | Not Found - Resource doesn't exist |
422 | Unprocessable Entity - Validation failed |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error |
Core Endpoints
Events
POST/v1/events/trigger
Trigger a notification workflow:
typescript
const response = await fetch('https://api.nexus.dev/v1/events/trigger', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'order-shipped',
to: {
subscriberId: 'user_123',
email: '[email protected]'
},
payload: {
orderId: '12345',
trackingNumber: 'TRK-789'
}
})
})
const data = await response.json()python
import requests
response = requests.post(
'https://api.nexus.dev/v1/events/trigger',
headers={
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json'
},
json={
'name': 'order-shipped',
'to': {
'subscriberId': 'user_123',
'email': '[email protected]'
},
'payload': {
'orderId': '12345',
'trackingNumber': 'TRK-789'
}
}
)
data = response.json()bash
curl -X POST https://api.nexus.dev/v1/events/trigger \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"name": "order-shipped",
"to": {
"subscriberId": "user_123",
"email": "[email protected]"
},
"payload": {
"orderId": "12345",
"trackingNumber": "TRK-789"
}
}'Subscribers
POST/v1/subscribers
Create or update a subscriber:
typescript
const subscriber = await fetch('https://api.nexus.dev/v1/subscribers', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json',
},
body: JSON.stringify({
subscriberId: 'user_123',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
data: {
plan: 'premium',
signupDate: '2024-01-01'
}
})
})python
subscriber = requests.post(
'https://api.nexus.dev/v1/subscribers',
headers={
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json'
},
json={
'subscriberId': 'user_123',
'email': '[email protected]',
'firstName': 'John',
'lastName': 'Doe',
'data': {
'plan': 'premium',
'signupDate': '2024-01-01'
}
}
)bash
curl -X POST https://api.nexus.dev/v1/subscribers \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"subscriberId": "user_123",
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"data": {
"plan": "premium",
"signupDate": "2024-01-01"
}
}'GET/v1/subscribers/{subscriberId}
Get subscriber details:
typescript
const subscriber = await fetch('https://api.nexus.dev/v1/subscribers/user_123', {
headers: {
'Authorization': 'Bearer sk_live_...'
}
})
const data = await subscriber.json()python
subscriber = requests.get(
'https://api.nexus.dev/v1/subscribers/user_123',
headers={'Authorization': 'Bearer sk_live_...'}
)
data = subscriber.json()bash
curl -H "Authorization: Bearer sk_live_..." \
https://api.nexus.dev/v1/subscribers/user_123Messages
GET/v1/messages
List sent messages:
typescript
const messages = await fetch('https://api.nexus.dev/v1/messages?subscriberId=user_123', {
headers: {
'Authorization': 'Bearer sk_live_...'
}
})
const data = await messages.json()python
messages = requests.get(
'https://api.nexus.dev/v1/messages',
params={'subscriberId': 'user_123'},
headers={'Authorization': 'Bearer sk_live_...'}
)
data = messages.json()bash
curl -H "Authorization: Bearer sk_live_..." \
"https://api.nexus.dev/v1/messages?subscriberId=user_123"Pagination
List endpoints support pagination using cursor-based pagination:
Request Parameters
limit: Number of items to return (max 100, default 20)cursor: Cursor for the next page (returned in previous response)
Response Format
json
{
"data": [
{ "id": "1", "name": "Item 1" },
{ "id": "2", "name": "Item 2" }
],
"hasMore": true,
"nextCursor": "eyJ0aW1lc3RhbXAiOjE2OTQ..."
}Example
typescript
// First page
let response = await fetch('https://api.nexus.dev/v1/messages?limit=50', {
headers: { 'Authorization': 'Bearer sk_live_...' }
})
let data = await response.json()
// Next page
if (data.hasMore) {
response = await fetch(`https://api.nexus.dev/v1/messages?limit=50&cursor=${data.nextCursor}`, {
headers: { 'Authorization': 'Bearer sk_live_...' }
})
data = await response.json()
}python
# First page
response = requests.get(
'https://api.nexus.dev/v1/messages',
params={'limit': 50},
headers={'Authorization': 'Bearer sk_live_...'}
)
data = response.json()
# Next page
if data['hasMore']:
response = requests.get(
'https://api.nexus.dev/v1/messages',
params={'limit': 50, 'cursor': data['nextCursor']},
headers={'Authorization': 'Bearer sk_live_...'}
)
data = response.json()Filtering
Many endpoints support filtering using query parameters:
Common Filters
status: Filter by status (sent,delivered,failed)channel: Filter by channel (email,sms,push,in_app)createdAfter: ISO date stringcreatedBefore: ISO date string
Example
bash
GET /v1/messages?status=delivered&channel=email&createdAfter=2024-01-01T00:00:00ZIdempotency
For POST requests, you can include an Idempotency-Key header to ensure the request is only processed once:
http
POST /v1/events/trigger
Idempotency-Key: unique-key-123
Authorization: Bearer sk_live_...
Content-Type: application/jsonWebhooks
Nexus can send webhooks to notify your application about events:
Webhook Events
message.sent: Notification sent to providermessage.delivered: Provider confirmed deliverymessage.failed: Delivery failedmessage.opened: Recipient opened notificationmessage.clicked: Recipient clicked link
Webhook Payload
json
{
"id": "evt_123",
"type": "message.delivered",
"timestamp": "2024-01-15T10:30:00Z",
"data": {
"messageId": "msg_123",
"subscriberId": "user_123",
"channel": "email",
"status": "delivered",
"metadata": {
"providerId": "sendgrid",
"messageId": "abc123"
}
}
}Webhook Verification
Verify webhook authenticity using the signature:
typescript
import crypto from 'crypto'
function verifyWebhook(payload: string, signature: string, secret: string): boolean {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex')
return signature === `sha256=${expectedSignature}`
}python
import hmac
import hashlib
def verify_webhook(payload: str, signature: str, secret: str) -> bool:
expected_signature = 'sha256=' + hmac.new(
secret.encode(),
payload.encode(),
hashlib.sha256
).hexdigest()
return signature == expected_signatureError Handling
Error Codes
| Code | Description | Action |
|---|---|---|
INVALID_API_KEY | API key is invalid | Check your API key |
SUBSCRIBER_NOT_FOUND | Subscriber doesn't exist | Create subscriber first |
WORKFLOW_NOT_FOUND | Workflow doesn't exist | Check workflow ID |
VALIDATION_ERROR | Invalid request data | Fix validation errors |
RATE_LIMIT_EXCEEDED | Too many requests | Implement backoff |
PROVIDER_ERROR | External provider error | Check provider status |
Retry Strategy
Implement exponential backoff for failed requests:
typescript
async function apiCallWithRetry(apiCall: () => Promise<Response>, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await apiCall()
if (response.ok) {
return response
}
if (response.status < 500 && response.status !== 429) {
// Client error, don't retry
throw new Error(`API call failed with status ${response.status}`)
}
if (attempt === maxRetries) {
throw new Error(`API call failed after ${maxRetries} attempts`)
}
// Wait before retrying (exponential backoff)
await new Promise(resolve => setTimeout(resolve, Math.pow(2, attempt) * 1000))
} catch (error) {
if (attempt === maxRetries) {
throw error
}
await new Promise(resolve => setTimeout(resolve, Math.pow(2, attempt) * 1000))
}
}
}python
import time
import requests
from typing import Callable
def api_call_with_retry(api_call: Callable, max_retries: int = 3):
for attempt in range(1, max_retries + 1):
try:
response = api_call()
if response.ok:
return response
if response.status_code < 500 and response.status_code != 429:
# Client error, don't retry
raise Exception(f"API call failed with status {response.status_code}")
if attempt == max_retries:
raise Exception(f"API call failed after {max_retries} attempts")
# Wait before retrying (exponential backoff)
time.sleep(2 ** attempt)
except Exception as e:
if attempt == max_retries:
raise e
time.sleep(2 ** attempt)SDK Libraries
For easier integration, use our official SDKs:
📦 @nexus/node
🐍 nexus-python
💎 nexus-ruby
🐘 nexus-php
🐹 nexus-go
☕ nexus-java
OpenAPI Specification
Download our complete OpenAPI specification:
Testing
Use our test API key to experiment without sending real notifications:
bash
export NEXUS_API_KEY="sk_test_1234567890abcdef"