A portal or AI-agent session
const url = 'https://stitch-collector-dev.magic-blocks.workers.dev/v1/session';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"session_type":"ai_agent","external_session_ref":"mb-sess-77120","octopus_id":"88213","anon_id":"3f1a8c2e-9b4d-4a71-8e2f-0c5d6a7b8e91","started_at":1772539200000,"ended_at":1772539980000,"ai_channel":"web_chat","ai_direction":"inbound","ai_agent_id":"agent-dscr-qualifier","ai_agent_version":"v3.2"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://stitch-collector-dev.magic-blocks.workers.dev/v1/session \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "session_type": "ai_agent", "external_session_ref": "mb-sess-77120", "octopus_id": "88213", "anon_id": "3f1a8c2e-9b4d-4a71-8e2f-0c5d6a7b8e91", "started_at": 1772539200000, "ended_at": 1772539980000, "ai_channel": "web_chat", "ai_direction": "inbound", "ai_agent_id": "agent-dscr-qualifier", "ai_agent_version": "v3.2" }'Sessions that do not happen in a browser we track: an authenticated portal, an AI agent’s conversation. Sent by whichever system runs the session, or a middleware in front of it. Unlike /v1/collect, a malformed payload is a loud 400: a silent success would hide a broken integration for weeks.
Authorizations
Section titled “Authorizations ”Request Body required
Section titled “Request Body required ”object
Your id for the session. The idempotency key: re-sending returns the existing session_id.
The contact, when known.
The page’s anonymous id when the session began on one of our pages, so the chat carries the visitor’s referral history.
Epoch milliseconds.
web_chat, voice, sms, …
Responses
Section titled “ Responses ”Recorded (or found, when external_session_ref was seen before).
object
Example generated
{ "session_id": "example"}Malformed JSON or a payload missing what the endpoint needs. The body says which.
object
What was wrong, in a sentence. A 401 carries unauthorized and nothing more.
Example generated
{ "error": "example"}No key, or a key the collector does not know. Nothing was written.
object
What was wrong, in a sentence. A 401 carries unauthorized and nothing more.
Example
{ "error": "unauthorized"}Only the method shown is served.