Skip to content
ModuleM6 — Integrations and live data
After this session you canKeep an outside screen current without polling, and know exactly what the live channel does and does not promise.
TimeFacilitated: 39 min · On your own: 39 min
Before you startM6-S1. Hala Mansour’s session in .tokens.json and your refresh.mjs (M5-S2). Ziad Karam waits at Job offer. Samir Khoury in a private window.
Go deeperReal-time: live events and calls · Subscribing to events · Data model & events: socket messages

◆ Orientation (1 min) — HR’s wall screen

Section titled “◆ Orientation (1 min) — HR’s wall screen”

HR wants a screen on the office wall that shows applications moving as it happens (R-12). Polling the API every few seconds would be slow and wasteful. The platform pushes changes to connected clients instead: the same channel the portal uses to refresh an open record. In M5-S2 you decided the screen signs in as a person; now you connect it.

The live channel speaks Socket.IO version 4 (a plain WebSocket client cannot connect), on the tenant’s own host. The credential is an OAuth access token, the same one you use for HTTP, or an anonymous token on public pages. An API token cannot open the channel. The token is checked once, at the handshake: an open connection is not closed when the token expires, but every reconnect is a new handshake, so supply the token through a function that always returns the current one.

A new connection receives nothing until it subscribes, and each subscription has an acknowledgement: wait for it, because some failed subscriptions report no error.

You sendWithAcknowledgementYou then receive
subscribeToNotificationsnothing: the token says who you aresubscribedToNotificationsThe person’s notifications, and their jobs’ completions
entries/subscribe-to-entry{ entityId, entryId }subscribedToEntryChanges to that record
subscribeToJobExecution{ messageId } of a job you startedsubscribedToJobExecutionThe job’s completion
EventMeans
entries/value-updatedField values changed; it may carry the record’s new updateIdentifier
entries/workflow-updatedA step was reached or left, an action taken, an owner changed
entries/comments-updatedA comment was added or changed
entries/archived, entries/restoredThe record was archived or restored
notificationA notification for the signed-in person

The events are the record-lifecycle and workflow events of M6-S1, delivered to whoever is subscribed.

The channel is push-only and best-effort. Events are sent only while you are subscribed; nothing is kept for a disconnected client, and there is no replay. So after every connect or reconnect: subscribe again, then re-read over HTTP what you show. Writes and authoritative reads always go through the HTTP API. Notifications arrive from every space the person belongs to; a custom client filters them on the notification’s space.

sequenceDiagram
  participant S as Wall screen
  participant T as Tenant host
  S->>T: connect (access token)
  S->>T: entries/subscribe-to-entry
  T-->>S: subscribedToEntry (ack)
  T-->>S: entries/value-updated …
  Note over S,T: network drops, events are lost
  S->>T: reconnect (fresh token)
  S->>T: subscribe again
  S->>T: re-read the record over HTTP

What to notice: the re-read after reconnect is what makes a best-effort channel correct; the events only tell you when to look.

Goal. A small program, signed in as Hala Mansour, that shows Ziad Karam’s application changing live and Hala’s notifications as they arrive, and that survives a reconnect.

Before you start. A terminal in your careers-client folder, with BASE set.

  1. Install the client library: npm install socket.io-client@4.

  2. Find the two ids: read Ziad Karam’s application as Hala through HR view:

    Terminal window
    node refresh.mjs
    curl -s -G "$BASE/api/v1/v/$HRVIEW/v3/entities/job_application/entries" \
    -H "Authorization: Bearer $(jq -r .access_token .tokens.json)" \
    --data-urlencode 'search=Ziad' --data-urlencode 'filterCriteria={"limit":1}' \
    | jq -r '.entries[0] | "export ENTITY_ID=\(.dataEntity) ENTRY_ID=\(.id)"'

    Run the line it prints.

  3. Create live-board.mjs:

    import fs from 'node:fs';
    import { io } from 'socket.io-client';
    const { BASE, ENTITY_ID, ENTRY_ID } = process.env;
    const currentToken = () => JSON.parse(fs.readFileSync('.tokens.json', 'utf8')).access_token;
    const socket = io(BASE, {
    transports: ['websocket', 'polling'],
    auth: (cb) => cb({ token: currentToken() }), // a fresh token on every reconnect
    });
    socket.on('connect', () => {
    console.log('connected: subscribing (and a real board would re-read over HTTP now)');
    socket.emit('subscribeToNotifications');
    socket.emit('entries/subscribe-to-entry', { entityId: ENTITY_ID, entryId: ENTRY_ID });
    });
    socket.on('subscribedToNotifications', (a) => console.log('ack: notifications for', a.userId));
    socket.on('subscribedToEntry', (a) => console.log('ack: watching entry', a.entryId));
    socket.on('connect_error', (err) => console.error('refused:', err.message));
    socket.on('error', (e) => console.error('subscription error:', e.message));
    socket.on('disconnect', (reason) => console.log('disconnected:', reason));
    for (const event of ['entries/value-updated', 'entries/workflow-updated', 'entries/comments-updated', 'notification']) {
    socket.on(event, (payload) => {
    console.log(new Date().toISOString(), event, JSON.stringify(payload).slice(0, 160));
    });
    }
  4. Run node live-board.mjs. You see connected and both acknowledgements.

  5. As Samir Khoury, open Ziad Karam at Job offer and change Base salary to 12500; save. The board prints entries/value-updated, and a moment later another one when your Function’s reaction updates Offered gross.

  6. As Samir Khoury, attach an Offered contract and select Send job offer. The board prints entries/workflow-updated.

  7. Turn your computer’s network off for ten seconds and on again. The board prints disconnected, then connected and both acknowledgements again.

  8. Stop the board. Start it once more with your API token instead: replace currentToken() with process.env.TOKEN. It prints refused: an API token cannot open the channel. Put the line back.

Check.

  • Both subscriptions were acknowledged before you changed anything.
  • A field change and a workflow step each arrived as their own event.
  • The Function’s update arrived as a second value event, without you doing anything.
  • After the network came back, the board resubscribed by itself.
  • The API token was refused at the handshake.

Pass condition. The board shows Ziad Karam’s changes as they happen, recovers its subscriptions after a reconnect, and you can show that only an OAuth token opens it.

If something goes wrong

What you seeWhat to do
refused: Invalid token with Hala’s tokenIt expired: run node refresh.mjs and start again.
Connected, but no acknowledgement for the entryAn id is missing or wrong; the board would print subscription error. Repeat step 2.
Nothing arrives when Samir savesYou subscribed to a different record, or the save did not change a value.
Tenant not resolvedBASE is not the tenant’s own host.
Model answer

The board connects with Hala’s access token, supplied by a function so that every reconnect handshake gets the current one, subscribes in its connect handler so that subscriptions are restored after any reconnect, and waits for both acknowledgements. Samir’s save produced one value event, the Function’s chained update a second, and the offer a workflow event. A real wall screen would also re-read the record over HTTP in the connect handler, because anything that happened while it was offline was not kept for it. The API token is refused at the handshake, which is why M5-S2 gave the screen a person’s OAuth session.

◇ Worked scenario (1 min) — Monday morning’s frozen screen

Section titled “◇ Worked scenario (1 min) — Monday morning’s frozen screen”

On Monday the wall screen still shows Friday’s figures, though it is connected and shows no error. Diagnose before reading on.

What happened. The office network restarted on Saturday. The program reconnected, as yours does, but its subscriptions were made once, at start-up, not in the connect handler: the new connection subscribed to nothing, so nothing arrived. Fix one: subscribe on every connect.

What it would still have missed. Even resubscribed, it would not know what changed while it was offline: the channel keeps nothing. Fix two: re-read the shown records over HTTP after every connect, then let events keep them current.

What would have kept it silent for a year. Its token was read once at start-up and cached; a reconnect after an hour would have been refused. Fix three: give the connection a function that returns the current token, and keep the session refreshed.

✓ Practice (5 min) — Check your understanding

Section titled “✓ Practice (5 min) — Check your understanding”
PracticeChoose one answer.

A background service that calls the API with an API token also wants live updates. What does it need?

  1. Explanation for A

    ✓ Correct

    Correct: the channel accepts OAuth access tokens (or anonymous ones on public pages) only. See connecting.

  2. Explanation for B

    ✗ Incorrect

    Not this one: an API token is refused at the handshake. See connecting.

  3. Explanation for C

    ✗ Incorrect

    Not this one: the channel speaks Socket.IO, which a plain WebSocket client cannot use. See connecting.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

A client subscribes to a record, and the subscription silently does nothing. What should the client have done?

  1. Explanation for A

    ✗ Incorrect

    Not this one: repeating a bad subscription repeats the problem. See subscribing.

  2. Explanation for B

    ✓ Correct

    Correct: some failed subscriptions report no error, so only the acknowledgement proves it. See subscribing.

  3. Explanation for C

    ✗ Incorrect

    Not this one: a subscription is sent over a connection, so it needs one that is already open. See subscribing.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

A board was offline for ten minutes. When it reconnects, what does it receive about those ten minutes?

  1. Explanation for A

    ✗ Incorrect

    Not this one: the channel keeps nothing for a disconnected client. See what it promises.

  2. Explanation for B

    ✗ Incorrect

    Not this one: there is no summary; the client must find out itself. See what it promises.

  3. Explanation for C

    ✓ Correct

    Correct: the channel is best-effort with no replay, so re-reading after reconnect is the client’s job. See what it promises.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeDecide whether the statement is true or false.

An open live connection is closed when the access token used for its handshake expires.

  1. Explanation for A

    ✗ Incorrect

    Not this one: the token is checked once, at the handshake; the open connection continues. See connecting.

  2. Explanation for B

    ✓ Correct

    Correct: it stays open, but every reconnect is a new handshake that needs a current token. See connecting.

Check your answer

The correct answer is B (False). Open the explanation under each option to see why.

You connected a live client with the right credential, watched record and workflow events arrive, and designed it to recover from the channel’s limits. After Module 6 you can connect the suite to the outside world in both directions: outbound webhooks with a clear contract, and live clients that stay current.

Next. Module 7 secures everything you built: who sees what, what automations and integrations may reveal, and which credential each caller holds.