Apprvd.app

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
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.

FieldTypeWhat it is
eventsarray, 1–100The events, below. Required.
appInstanceIdstring ≤ 128Firebase Analytics' app instance id for this install.
platformios | android | webWhere the app runs.
appVersionstring ≤ 32The app's version: letters, digits, . _ + -
sdkVersionstring ≤ 32Your client's own version.
adTokenbase64Apple's AdServices token, once per install.

An event

FieldTypeWhat it is
idstring, 8–64Unique per event. A retry repeats both id and ts: duplicates are dropped on the pair. The SDKs use <millis>-<hex>. Required.
namestringLetters, digits, underscores, up to 60. Required.
tsintegerMilliseconds since the epoch, device clock. Required.
deviceIdstring ≤ 128A 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.
userIdstring ≤ 128The signed-in account, or omitted.
paramsobjectJSON; names of 1–40 characters; under 8 KB as JSON.

Responses

StatusBodyMeaning
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-AfterRate limit, or the key's daily budget. Keep the batch and retry after the header's seconds.
5xxanyA server error. Keep the batch and retry later with the same ids and ts.
  • ts is kept within limits: up to 7 days in the past and 5 minutes ahead; anything outside is clamped to the edge.
  • The newest userId in a batch is linked to its deviceId; a later batch with no userId never 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.

200 OK
{
  "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:

  1. A key that isn't in the config: return the fallback. shipped: return its winner.
  2. 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.
  3. Keep that answer for the rest of the session.
  4. On the first answer for a running test in a session, send apprvd_exposure with the deviceId you hashed, and params exp (the key) and variant.
TypeScript
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
}