Stream
Events pushed over a WebSocket, with replay.
Open the event stream
GET/v1/ws
Access key: an API key, or a correctly scoped app token where delegated access is allowed; console sessions are refused.
A WebSocket that pushes events as they happen, the same payload as a webhook plus delivered_at and attempt. Authenticate with the Authorization header, or ?token=dm_... for clients that cannot set headers; an app access token needs events:read and mail:read, and sessions are not accepted. Then send JSON frames (see StreamClientFrame): subscribe, with optional inbox_ids, event_types and last_event_id to replay up to 100 missed events; unsubscribe; ping. Limits: 10 connections per account (the next is closed with 4008), 30 frames per 10 seconds per connection (4029); a revoked key, a deleted inbox, or an app access token that ran out or was revoked closes its connections with 4001. A failed push is not retried over the socket: reconnect with last_event_id to catch up, with a renewed token when it was an app's.
OAuth: allowed with all of events:read, mail:read. App permissions apply in addition to account and resource checks.
Also available as client.stream in TypeScript and doorman events tail on the command line.
Parameters
tokenstring, in queryoptionalThe API key, for clients that cannot set the Authorization header. Example:
dm_....Upgrade"websocket", in headerrequiredwebsocket.
Answers 101: Switching protocols: the stream is open.
Frames the client sends: StreamClientFrame
One of:
StreamSubscribe
Start receiving events, for everything the key can see or a narrower set. Subscriptions accumulate.
type"subscribe"requiredinbox_idsstring[]optionalUp to 32 inbox ids, all of them the key's.
event_types("message.received" | "message.sent" | "thread.updated" | "inbox.created" | "inbox.deleted" | "delivery.failed" | "message.held" | "send.held" | "send.discarded" | "sign_in.requested" | "sign_in.completed")[]optionalOnly these event types; absent or empty means all.
last_event_idstringoptionalReplay every event after this one (up to 100, filtered by the subscription) before live events. Example:
evt_01jc5e5f6g7h8j9k0m1n2p3q4r
StreamUnsubscribe
Stop receiving events: everything, or specific inboxes.
type"unsubscribe"requiredinbox_idsstring[]optionalThe inboxes to stop receiving for; absent or empty stops everything.
StreamPing
A keepalive the edge answers with pong without waking the stream; send one every 30 to 60 seconds through idle proxies.
type"ping"required
Frames the server sends: StreamServerFrame
One of:
StreamSubscribed
The subscription in force after a subscribe frame; empty arrays mean all.
type"subscribed"requiredinbox_idsstring[]requiredevent_typesstring[]required
StreamUnsubscribed
The answer to an unsubscribe frame, echoing the inboxes it named.
type"unsubscribed"requiredinbox_idsstring[]required
StreamPong
The answer to a ping.
type"pong"required
StreamError
A frame that could not be honoured; the connection stays open.
type"error"requiredmessagestringrequired
StreamEvent
An event as the stream frames it: the webhook payload plus when it was pushed. attempt is always 1; a missed frame is recovered with last_event_id, not retried.
No fields.
Close codes
| Close code | Reason |
|---|---|
4001 | unauthorized |
4008 | connectionLimit |
4029 | rateLimit |
Errors
| Status | Error | Meaning |
|---|---|---|
| 401 | unauthorized | The credential was missing, malformed, revoked or belongs to an inactive account. |
| 403 | insufficient_scope | The app's token lacks a required scope, or the operation cannot be delegated. |
| 426 | upgrade_required | The stream needs a WebSocket upgrade. |
| 500 | internal_error | Something went wrong on the server. |
import WebSocket from "ws";
const socket = new WebSocket("wss://api.doorman.fyi/v1/ws", { headers: { authorization: `Bearer ${process.env.DOORMAN_API_KEY}` } });
// A client that cannot set headers (a browser) passes the key as ?token=dm_... instead.
socket.addEventListener("open", () => socket.send(JSON.stringify({"type":"subscribe","inbox_ids":["inb_01jc4q7w9k2m5n8p3r6t1v4x7z"]})));
socket.addEventListener("message", (message) => {
const frame = JSON.parse(String(message.data));
if (frame.type === "subscribed") console.log("subscribed", frame.inbox_ids);
if (frame.event === "message.received") console.log(frame.event_id, frame.message.subject);
});import asyncio, json, os
import websockets
async def main():
headers = {"authorization": f"Bearer {os.environ['DOORMAN_API_KEY']}"}
async with websockets.connect("wss://api.doorman.fyi/v1/ws", additional_headers=headers) as socket:
await socket.send(json.dumps({"type": "subscribe", "inbox_ids": ["inb_01jc4q7w9k2m5n8p3r6t1v4x7z"]}))
async for raw in socket:
frame = json.loads(raw)
if frame.get("event") == "message.received":
print(frame["event_id"], frame["message"]["subject"])
asyncio.run(main())
