REST API v1

Developer API

Access your Castlytics data programmatically. Read campaign stats, attribution results, and conversions from any application.

Authentication

All requests to the Castlytics API require a secret API key. Generate one from your Settings → Developer API section.

Pass the key in the Authorization header:

Authorization: Bearer sk_live_your_api_key_here

Keep your API key secret

Never expose your secret key in client-side code or public repositories. API keys are shown once on creation and cannot be recovered.

Base URL

https://castlytics.app/api/v1

All endpoints below are relative to this base URL. The API accepts and returns JSON.

Endpoints

MethodEndpoint
GET/workspace
GET/campaigns
GET/campaigns/:id
GET/campaigns/:id/stats
GET/conversions

Code Examples

cURL — list campaigns

curl https://castlytics.app/api/v1/campaigns \
  -H "Authorization: Bearer sk_live_your_api_key_here"

JavaScript (fetch) — campaign stats

const res = await fetch(
  'https://castlytics.app/api/v1/campaigns/CAMPAIGN_ID/stats',
  {
    headers: {
      Authorization: 'Bearer sk_live_your_api_key_here',
    },
  }
);
const { data } = await res.json();
console.log(data.clicks, data.revenue, data.roas);

JavaScript — paginated conversions

const res = await fetch(
  'https://castlytics.app/api/v1/conversions?limit=100&offset=0',
  { headers: { Authorization: 'Bearer sk_live_your_api_key_here' } }
);
const { data, total } = await res.json();
console.log(`${data.length} of ${total} conversions`);

Response Format

All successful responses return JSON with a data key containing the result. Errors return an error string.

// Success
{ "data": { ... } }

// List
{ "data": [...], "total": 312, "limit": 50, "offset": 0 }

// Error
{ "error": "Unauthorized" }   // HTTP 401
HTTP StatusMeaning
200Success
401Missing or invalid API key
404Resource not found
400Bad request (validation error)

Get your API key

Generate a secret key from your settings dashboard.

Go to Settings →