API Reference

Complete reference for the Castopia Partner API v1. All endpoints use JSON and authenticate via x-api-key header.

Authentication

Include your API key in every request using either method:

bash
# Header method (recommended)
curl -H "x-api-key: sk_live_your_key_here" ...

# Bearer method
curl -H "Authorization: Bearer sk_live_your_key_here" ...

Get your API key from Settings → API Keys. Partner endpoints require an active partner account.

Base URL

text
https://app.castopia.ai

Marketing (One-Call)

The core endpoint. Submit content and get a full marketing campaign created automatically.

Customers

Manage your customers. Each customer gets their own isolated organization, project, and knowledge base.

Campaigns & Analytics

View campaign performance and content analytics for your customers or your own org.

Embeddable Dashboard

Generate tokens to embed analytics dashboards in your product.

Usage & Billing

Monitor API usage and billing across all your customers.

Webhooks

Configure webhooks to receive real-time notifications when events occur.

Error Codes

CodeStatusDescription
MISSING_API_KEY401No API key provided
INVALID_API_KEY401Key is invalid, expired, or revoked
NO_ORGANIZATION400No org linked to the API key
NOT_A_PARTNER403Endpoint requires a partner account
PARTNER_INACTIVE403Partner account pending or suspended
CUSTOMER_NOT_FOUND404Customer ID or externalId not found
CUSTOMER_EXISTS409A customer with this externalId already exists

Webhook Verification

Verify webhook signatures using HMAC-SHA256 with your webhook secret:

javascript
const crypto = require('crypto');

function verifyWebhook(body, signature, secret) {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(body)
    .digest('hex');
  return signature === expected;
}

// In your webhook handler:
app.post('/webhooks/castopia', (req, res) => {
  const signature = req.headers['x-castopia-signature'];
  if (!verifyWebhook(JSON.stringify(req.body), signature, WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }
  // Process event...
  const { event, data } = req.body;
});