Create a realtime token
POST/api/patient/provider-chat/socket-token
A short-lived token for the realtime chat connection. With it your app sends and receives care-team messages as the person, and your key never reaches the device. Needs the write scope.
The token works only for the chat connection (the REST API refuses it) and expires after 10 minutes: ask for a new one each time you connect.
Body: none.
Response 200: { token, tokenType: 'Bearer', scope: 'chat', viewerType: 'patient', expiresIn: 600, socketPath: '/socket.io' }.
Connecting (Socket.IO v4):
const socket = io(BASE_URL, {
path: '/socket.io', transports: ['websocket', 'polling'],
auth: (cb) => getToken().then((token) => cb({ token })), // a new token on every connect
});
socket.emit('room:join', {}, (ack) => { /* ack.ok, ack.canSend */ });
socket.emit('message:send', { body, clientMsgId }, (ack) => { /* ack.ok, ack.message */ });
socket.emit('message:read', {});
socket.on('message:new', (m) => { /* add it; skip one whose clientMsgId you already have */ });
socket.on('unread:update', (u) => { /* u.unreadCount */ });
Request
Responses
- 200
- 400
- 401
- 409
- 429
- 500
Success
Bad Request
Unauthorized (X-Api-Key missing, malformed, unknown or disabled)
Conflict
Too Many Requests (rate limit exceeded)
Internal Server Error