Realtime updates

Depfloy pushes project events over a WebSocket that speaks the Pusher protocol. An API token is enough to connect, authorize a project channel and receive the events the dashboard uses.

AUTH Authorization: Bearer {API_KEY} Create a token →

1. Read the connection values #

GET /api/v1/realtime/config returns the public connection values. The app secret is never part of the response.

GET /api/v1/realtime/config Request
cURL
curl https://app.depfloy.com/api/v1/realtime/config \
  -H "Authorization: Bearer {API_KEY}" \
  -H "Accept: application/json"
Response
{
  "protocol": "pusher",
  "key": "{APP_KEY}",
  "host": "{WS_HOST}",
  "port": 443,
  "scheme": "https",
  "auth_endpoint": "https://app.depfloy.com/api/v1/broadcasting/auth"
}

Read these values at startup instead of hard-coding them.

2. Authorize the project channel #

Each project has the private channel private-project.{id}. A Pusher client authorizes it by posting socket_id and channel_name to auth_endpoint with your token in the Authorization header. The request succeeds when the token’s owner can see the project and the token has project:read, and returns 403 otherwise. To act in another organization you belong to, send its id in the X-Organization header, as on other API calls. These requests count toward the API rate limit.

3. Subscribe #

With pusher-js (Node.js or the browser):

import Pusher from 'pusher-js';

const headers = { Authorization: `Bearer ${process.env.DEPFLOY_TOKEN}`, Accept: 'application/json' };
const config = await fetch('https://app.depfloy.com/api/v1/realtime/config', { headers }).then((r) => r.json());

const pusher = new Pusher(config.key, {
  cluster: '',
  wsHost: config.host,
  wsPort: config.port,
  wssPort: config.port,
  forceTLS: config.scheme === 'https',
  enabledTransports: ['ws', 'wss'],
  channelAuthorization: { endpoint: config.auth_endpoint, transport: 'ajax', headers },
});

const channel = pusher.subscribe(`private-project.${projectId}`);

channel.bind('App\\Events\\OperationCompletedEvent', (event) => {
  if (event.operation === 'ssl-setup') {
    console.log(event.data.domain_id, event.status, event.message);
  }
});

SSL setup events #

Every change of a domain’s SSL setup is sent as App\Events\OperationCompletedEvent with operation set to ssl-setup:

status string

queued, dns_pending, issuing_certificate, ready or failed.

message string

Why the setup failed; an empty string for the other statuses.

data object

project_id and domain_id.

Payload (fields used here)
{
  "channel": "project.14532",
  "operation": "ssl-setup",
  "status": "failed",
  "message": "DNS has not reached the server. Point the domain to the server, then retry SSL setup.",
  "data": { "project_id": 14532, "domain_id": 136526 }
}

Events sent while you are disconnected are not replayed. After a reconnect, read the current state with List domains, which returns the same status and reason in ssl_setup.

The channel also carries other events the dashboard uses. Only the ssl-setup payload above is described here.