HTTP API
The two endpoints the SDKs call, for a platform without an SDK or a backend that sends events itself.
Use the SDKs where you can: they batch, retry, and assign experiment variants the way the server counts them. This is the wire format underneath them.
Authentication
Both endpoints take the app's write key as a bearer token: Authorization: Bearer pk_…. A key reaches one app and can only send events and read its experiment config. An app's key is shared by every install and your backend, so its requests a minute scale with the plan: 250 on Free, 2,500 on Indie, 10,000 on Breakout, both endpoints together.
POST /api/ingest
A batch of events from one install.
curl https://platform.apprvd.app/api/ingest \
-H "Authorization: Bearer pk_…" \
-H "Content-Type: application/json" \
-d '{
"platform": "ios",
"appVersion": "2.4.1",
"events": [
{
"id": "1763380800000-9f2c4a1b",
"name": "lesson_completed",
"ts": 1763380800000,
"deviceId": "6f1e…",
"userId": "u_123",
"params": { "lesson": "intro", "score": 87 }
}
]
}'Use the current time in milliseconds for ts and the id's prefix; a ts more than 7 days old is stored as 7 days ago.
The batch
Batch-level fields describe the install, so they are sent once rather than on every event. A bad platform, appVersion, sdkVersion or adToken is dropped on its own; a bad appInstanceId refuses the batch.
| Field | Type | What it is |
|---|---|---|
| events | array, 1–100 | The events, below. Required. |
| appInstanceId | string ≤ 128 | Firebase Analytics' app instance id for this install. |
| platform | ios | android | web | Where the app runs. |
| appVersion | string ≤ 32 | The app's version: letters, digits, . _ + - |
| sdkVersion | string ≤ 32 | Your client's own version. |
| adToken | base64 | Apple's AdServices token, once per install. |
An event
| Field | Type | What it is |
|---|---|---|
| id | string, 8–64 | Unique per event. A retry repeats both id and ts: duplicates are dropped on the pair. The SDKs use <millis>-<hex>. Required. |
| name | string | Letters, digits, underscores, up to 60. Required. |
| ts | integer | Milliseconds since the epoch, device clock. Required. |
| deviceId | string ≤ 128 | A stable install id. Experiments count only exposures that carry one, and the account link and adToken are recorded only for a batch that has one. |
| userId | string ≤ 128 | The signed-in account, or omitted. |
| params | object | JSON; names of 1–40 characters; under 8 KB as JSON. |
Responses
| Status | Body | Meaning |
|---|---|---|
| 200 | { "accepted": n } | Stored. A retried event (same id and ts) is accepted and ignored. |
| 400 | { "error": … } | Not JSON, or the batch or an event breaks a rule; the message names the first rule broken, not which event. The whole batch is refused and a retry won't pass: drop it. |
| 401 | { "error": "invalid write key" } | Missing or wrong key. |
| 413 | { "error": "body too large" } | Over about 2.6 MB, more than any batch the SDKs build. |
| 429 | { "error": … } + Retry-After | Rate limit, or the key's daily budget. Keep the batch and retry after the header's seconds. |
| 5xx | any | A server error. Keep the batch and retry later with the same ids and ts. |
tsis kept within limits: up to 7 days in the past and 5 minutes ahead; anything outside is clamped to the edge.- The newest
userIdin a batch is linked to itsdeviceId; a later batch with nouserIdnever unlinks it.
GET /api/sdk/config
What a device needs to answer variant(key, fallback): the app's running tests and each decided key's winner. Ask once per launch; it may be cached for 60 seconds.
{
"experiments": {
"paywall_copy": {
"id": "3f0c2a9e-…",
"status": "running",
"variants": [
{ "name": "long", "weight": 50 },
{ "name": "short", "weight": 50 }
]
},
"onboarding_length": { "status": "shipped", "winner": "three_steps" }
}
}Assigning a variant
Do it exactly as the SDKs do, or a device's variant won't match across platforms:
- A key that isn't in the config: return the fallback.
shipped: return itswinner. running: hash the UTF-8 bytes of<deviceId>:<experiment id>with 32-bit FNV-1a, take it mod 100, and walk the variants' cumulative weights to the first one whose edge is above it.- Keep that answer for the rest of the session.
- On the first answer for a running test in a session, send
apprvd_exposurewith thedeviceIdyou hashed, and paramsexp(the key) andvariant.
function bucketOf(deviceId: string, experimentId: string): number {
let h = 0x811c9dc5;
for (const byte of new TextEncoder().encode(`${deviceId}:${experimentId}`)) {
h ^= byte;
h = Math.imul(h, 0x01000193) >>> 0;
}
return h % 100;
}
function variantFor(bucket: number, variants: { name: string; weight: number }[]) {
let edge = 0;
for (const v of variants) {
edge += v.weight;
if (bucket < edge) return v.name;
}
return null; // weights short of 100: use the fallback
}Access-Control-Allow-Origin: *, with Retry-After exposed), so a browser build such as Flutter web can call them with the write key. Events your backend sends count like any other, so give them the device id and account id of the install they belong to, and send one batch per install: a batch's newest userId is linked to its first deviceId. The write key ships in apps, so the server treats everything it receives as untrusted: experiment results count exposures from devices, and Apple Ads attribution is Apple's answer, never the batch's word.