Skip to content

POST /batch

POST/v1/collect/batchsession id

Stores one batch of events; idempotent per batch_id.

Field Type Rules
v number Must be 2.
session_id string From POST /session.
user_id string Must match the session's, else 409.
batch_id string 8 to 64 characters; unique per batch, reused on retry.
seq integer 0 or more; increases within a session.
events Event[] 1 to 5,000 events.
Request
POST /v1/collect/batch HTTP/1.1
Host: api.behavlabs.com
Content-Type: application/x-behavlabs-batch+deflate
// body: raw DEFLATE of the JSON below. Uncompressed bodies are accepted as
// application/json or text/plain (what sendBeacon sends).

{
  "v": 2,
  "session_id": "8649741cdcf3427eba8259d8b63e2bbb",
  "user_id": "u_8f3a91",
  "batch_id": "lq3k9x0c2m1f8a7b6d5e4c3b2a1f0e9d",
  "seq": 0,
  "events": [
    { "modality": "keystroke", "event_type": "keydown", "timestamp_ms": 1834.2,
      "key_code": "KeyA", "key_char": "Letter", "field_id": "email" },
    { "modality": "keystroke", "event_type": "keyup", "timestamp_ms": 1921.7,
      "key_code": "KeyA", "key_char": "Letter", "hold_ms": 87.5, "field_id": "email" },
    { "modality": "mouse", "event_type": "move", "timestamp_ms": 2040.0,
      "x": 612, "y": 344, "button": 0 }
  ]
}
Response
{ "session_id": "8649741c...", "batch_id": "lq3k9x0c...", "events_stored": 3, "duplicate": false }