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_hereGet 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
| Field | Type | Required | Description |
|---|---|---|---|
| type | string | Yes | track, page, or identify |
| event | string | For track | Event name |
| userId | string | * | Known user ID (userId or anonymousId required) |
| anonymousId | string | * | Anonymous device/session ID |
| timestamp | ISO 8601 | No | When event occurred (defaults to now) |
| properties | object | No | Custom event data |
| context | object | No | Page, 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
| Code | Meaning |
|---|---|
| 200, 201 | Success |
| 400 | Invalid request body |
| 401 | Missing or invalid Write Key |
| 429 | Rate limit exceeded |
| 500 | Server error (retry) |