Back to Docs

REST API

Send events from any backend, mobile app, or custom integration using HTTP requests.

Base URL

https://analytics.chatnationbot.com

Authentication

Include your Write Key in the X-Write-Key header:

POST /v1/capture HTTP/1.1
Host: analytics.chatnationbot.com
Content-Type: application/json
X-Write-Key: your_write_key_here

Get your Write Key from Settings → API Keys.

POST/v1/capture

Send a batch of events to the analytics collector.

Request Body

{
  "batch": [
    {
      "type": "track",
      "event": "Order Completed",
      "userId": "user_123",
      "timestamp": "2026-01-20T06:30:00.000Z",
      "properties": {
        "order_id": "ord_456",
        "total": 99.99,
        "currency": "USD"
      },
      "context": {
        "channel": "web"
      }
    }
  ]
}

Response (201 Created)

{
  "status": "success"
}

Event Types

track

Track a user action or event.

{
  "type": "track",
  "event": "Button Clicked",
  "userId": "user_123",
  "anonymousId": "anon_456",
  "timestamp": "2026-01-20T06:30:00.000Z",
  "properties": {
    "button_id": "signup",
    "color": "blue"
  }
}

page

Track a page view.

{
  "type": "page",
  "name": "Home",
  "userId": "user_123",
  "timestamp": "2026-01-20T06:30:00.000Z",
  "context": {
    "page": {
      "path": "/",
      "url": "https://example.com/",
      "title": "Home | My App"
    }
  }
}

identify

Link an anonymous user to a known user ID.

{
  "type": "identify",
  "userId": "user_123",
  "anonymousId": "anon_456",
  "timestamp": "2026-01-20T06:30:00.000Z",
  "traits": {
    "email": "user@example.com",
    "name": "John Doe",
    "plan": "premium"
  }
}

Field Reference

FieldTypeRequiredDescription
typestringYestrack, page, or identify
eventstringFor trackEvent name
userIdstring*Known user ID (userId or anonymousId required)
anonymousIdstring*Anonymous device/session ID
timestampISO 8601NoWhen event occurred (defaults to now)
propertiesobjectNoCustom event data
contextobjectNoPage, device, channel info

Code Examples

cURL

curl -X POST https://analytics.chatnationbot.com/v1/capture \
  -H "Content-Type: application/json" \
  -H "X-Write-Key: your_write_key" \
  -d '{
    "batch": [{
      "type": "track",
      "event": "Order Completed",
      "userId": "user_123",
      "properties": { "total": 99.99 }
    }]
  }'

Python

import requests

url = "https://analytics.chatnationbot.com/v1/capture"
headers = {
    "Content-Type": "application/json",
    "X-Write-Key": "your_write_key"
}

payload = {
    "batch": [{
        "type": "track",
        "event": "Order Completed",
        "userId": "user_123",
        "properties": {"total": 99.99}
    }]
}

response = requests.post(url, json=payload, headers=headers)
print(response.status_code)

Node.js

const response = await fetch(
  "https://analytics.chatnationbot.com/v1/capture",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Write-Key": "your_write_key"
    },
    body: JSON.stringify({
      batch: [{
        type: "track",
        event: "Order Completed",
        userId: "user_123",
        properties: { total: 99.99 }
      }]
    })
  }
);

Error Codes

CodeMeaning
200, 201Success
400Invalid request body
401Missing or invalid Write Key
429Rate limit exceeded
500Server error (retry)