Skip to main content

HTTP API

All requests need authentication via an API key (X-API-Key header) or a dashboard JWT (Authorization: Bearer).

The SDK uses the API key path. The key looks like ck_<8 hex>_<random> and is created in the dashboard.

Authentication headers​

HeaderRequired forDescription
X-API-KeySDKThe tenant's key, e.g. ck_8b8da955_a1b2c3d4e5f6
X-Tenant-DomainSDK (optional)The hostname the SDK is running on — needed to test a production key from localhost. The backend rejects requests from domains not on the tenant's allowlist.
AuthorizationDashboardJWT from the dashboard login flow.

Endpoints​

POST /v1/events​

Ingest a batch of events from the SDK.

curl -X POST https://api.nochurn.dev/v1/events \
-H "Content-Type: application/json" \
-H "X-API-Key: ck_..." \
-d '{"events": [...]}'

Request body:

{
"events": [
{
"eventId": "evt_abc123",
"userId": "user_xyz",
"sessionId": "sess_abc",
"type": "click",
"properties": { "element": "button.primary" },
"occurredAt": "2026-01-15T10:30:00.000Z"
}
]
}
  • events[].eventId — unique per event (SDK generates evt_<8 hex><random>)
  • events[].userId — the user's id (passed to NoChurn.init() or generated)
  • events[].sessionId — the session (generated once per page load)
  • events[].type — event type. Any string is accepted; the scoring rules only look at the ones they know (click, scroll, form_submit, pageview, billing_visit, js_error, session_start, session_end)
  • events[].properties — arbitrary key/value
  • events[].occurredAt — either an ISO timestamp or epoch ms

Batch limit: up to 20 events per request by default (the SDK batches automatically).

Response (200):

{
"ok": true,
"received": 20,
"deduped": 0,
"userId": "user_xyz",
"tenantId": "linux-managed"
}
  • received — events that were accepted
  • deduped — events that were skipped because they were already persisted (the SDK deduplicates automatically)
  • rejected — (only present when some events failed validation) an array with the index and the validation error, so you know exactly which events were dropped and why

Errors:

  • 401 — invalid API key format (does not start with ck_)
  • 403 — the domain in X-Tenant-Domain is not on the tenant's allowlist

POST /v1/users/identify​

Register (or claim) a user. The SDK calls this automatically when you pass a userId to NoChurn.init() or call identify().

curl -X POST https://api.nochurn.dev/v1/users/identify \
-H "Content-Type: application/json" \
-H "X-API-Key: ck_..." \
-d '{
"userId": "user_abc123",
"previousUserId": "anon_xyz",
"email": "[email protected]",
"preregistration": false
}'

Request body:

FieldRequiredDescription
userIdyesThe user id the SDK is using.
previousUserIdnoThe anonymous id the SDK generated before signup — events collected under that id are claimed by this user.
emailnoThe user's email address.
preregistrationnotrue if the SDK is creating a pre‑registration (the SDK saw an anonymous visitor before they signed up).

Response (200):

{
"ok": true,
"userId": "user_abc123",
"email": "[email protected]",
"domain": "app.your-company.com",
"registeredAt": "2026-01-15T10:35:00.000Z"
}

GET /v1/users/:userId/score​

Get a user's current churn score.

curl https://api.nochurn.dev/v1/users/user_abc123/score \
-H "X-API-Key: ck_..."

Response (200):

{
"userId": "user_abc123",
"score": 72,
"tier": "high",
"signals": {
"activity_drop_d7": true,
"activity_drop_d3": true,
"billing_page_time": true,
"js_errors": false,
"login_decay": false
},
"computedAt": "2026-01-15T11:00:00.000Z"
}
  • score — 0–100, the sum of all signals that fired
  • tier — low (0–39), medium (40–59), high (60–79), critical (80–100)
  • signals — the five signals and whether each contributed to the score
  • computedAt — when the score was last computed (or null if it has never been computed)

If the score has never been computed, it is computed on demand — the response includes the freshly computed score.


DELETE /v1/users/:userId​

Delete a user and all their events. This is the GDPR/LGPD right to erasure.

curl -X DELETE https://api.nochurn.dev/v1/users/user_abc123 \
-H "X-API-Key: ck_..."

Response (200):

{
"ok": true,
"userId": "user_abc123"
}

The request deletes:

  • The user's row in the users table
  • All events the user emitted
  • The user's score (if any)

GET /health​

Health check — used by Cloudflare Workers' automatic health monitoring. No authentication required.

curl https://api.nochurn.dev/health

Response (200):

{
"status": "ok",
"db": "ok",
"version": "0.1.0",
"time": "2026-01-15T11:00:00.000Z"
}
  • status — ok or degraded (the database probe failed)
  • db — ok or error

Error format​

All errors return a JSON body:

{
"code": "VALIDATION_ERROR",
"message": "...",
"details": { ... }
}
CodeHTTP statusMeaning
VALIDATION_ERROR400The request body does not match the schema.
AUTHENTICATION_ERROR401Invalid API key.
AUTHORIZATION_ERROR403Domain not on the tenant's allowlist (SDK-only).
NOT_FOUND404User not found.
RATE_LIMIT_ERROR429Too many requests (not currently enforced — see below).
INTERNAL_ERROR500Unhandled server error.

Rate limiting (not enforced)​

The configuration has RATE_LIMIT_PER_MINUTE but there is no middleware that enforces it yet. The SDK batches automatically (20 events per request), which already limits the request rate in practice. A future release will add proper throttling.