Skip to content

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.dev
text
https://your-domain.com/api
text
http://localhost:3001

Authentication ​

Nexus uses API keys for authentication. Include your API key in the Authorization header:

http
Authorization: Bearer sk_live_1234567890abcdef

API Key Types ​

TypeFormatEnvironmentDescription
Livesk_live_...ProductionFor production use
Testsk_test_...DevelopmentFor 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:

PlanRequests per minuteBurst limit
Free100200
Pro1,0002,000
Enterprise10,00020,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.0

Response 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 ​

CodeDescription
200Success
201Created
400Bad Request - Invalid input
401Unauthorized - Invalid API key
403Forbidden - Insufficient permissions
404Not Found - Resource doesn't exist
422Unprocessable Entity - Validation failed
429Too Many Requests - Rate limit exceeded
500Internal 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_123

Messages ​

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 string
  • createdBefore: ISO date string

Example ​

bash
GET /v1/messages?status=delivered&channel=email&createdAfter=2024-01-01T00:00:00Z

Idempotency ​

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/json

Webhooks ​

Nexus can send webhooks to notify your application about events:

Webhook Events ​

  • message.sent: Notification sent to provider
  • message.delivered: Provider confirmed delivery
  • message.failed: Delivery failed
  • message.opened: Recipient opened notification
  • message.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_signature

Error Handling ​

Error Codes ​

CodeDescriptionAction
INVALID_API_KEYAPI key is invalidCheck your API key
SUBSCRIBER_NOT_FOUNDSubscriber doesn't existCreate subscriber first
WORKFLOW_NOT_FOUNDWorkflow doesn't existCheck workflow ID
VALIDATION_ERRORInvalid request dataFix validation errors
RATE_LIMIT_EXCEEDEDToo many requestsImplement backoff
PROVIDER_ERRORExternal provider errorCheck 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"

Next Steps ​