Docs/Endpoints
Docs/REST API

Endpoints

Complete HTTP REST API specification for triggering events, querying channels, and managing connections.

REST API Endpoints

Socketo provides a Pusher-compatible HTTP REST API for triggering server-to-client events, querying channel occupancy, and managing connected users.


Base URLs

  • Socketo Cloud: https://api.socketo.dev
  • Socketo Local CLI: http://localhost:8787
  • Self-Hosted: https://<your-worker-domain>

Authentication

All REST endpoints under /apps/:id/* require Pusher Channels HMAC-SHA256 authentication passed as URL query parameters.

Required Query Parameters

ParameterTypeDescription
auth_keystringYour public application key.
auth_timestampnumberUnix timestamp in seconds (valid within ±600 seconds of server time).
auth_versionstringMust be exactly "1.0".
body_md5stringHex MD5 digest of the request body (required for POST, PUT, PATCH).
auth_signaturestringHMAC-SHA256 hash of METHOD\nPATH\nQUERY_STRING signed with app_secret.

Official Pusher server SDKs handle signature generation automatically. See Auth & Signatures to sign requests manually.


1. Trigger Event

Publish an event to one or more channels (up to 100 channels).

http
POST /apps/:id/events

Request Body

json
{
  "name": "new-message",
  "channels": ["chat-room-1", "chat-room-2"],
  "data": "{\"text\":\"Hello world!\",\"author\":\"Alice\"}",
  "socket_id": "1234.5678",
  "info": "user_count"
}
FieldTypeRequiredDescription
namestringYesEvent name.
datastringYesEvent payload as a serialized JSON string (max 10 KiB).
channelsstring[]Yes*Array of target channel names (1–100 channels). Provide either channels or channel.
channelstringYes*Single target channel name. Provide either channels or channel.
socket_idstringNoExclude a specific connection from receiving the broadcast.
infostringNoComma-separated metadata to return: user_count (presence channels only) or subscription_count (non-presence).

Response (200 OK)

json
{}

When info attribute is included in the request body:

json
{
  "channels": {
    "presence-room-1": {
      "user_count": 4
    }
  }
}

2. Batch Trigger Events

Publish up to 10 distinct events in a single network request.

http
POST /apps/:id/batch_events

Request Body

json
{
  "batch": [
    {
      "channel": "orders",
      "name": "order-created",
      "data": "{\"order_id\":\"ord_101\"}"
    },
    {
      "channel": "presence-lobby",
      "name": "announcement",
      "data": "{\"msg\":\"Server restart in 5m\"}",
      "info": "user_count"
    }
  ]
}
FieldTypeRequiredDescription
batchobject[]YesArray of 1 to 10 event objects.
batch[].channelstringYesTarget channel name.
batch[].namestringYesEvent name.
batch[].datastringYesSerialized JSON data payload (max 10 KiB).
batch[].socket_idstringNoExcluded socket ID.
batch[].infostringNoOptional metadata attributes (user_count, subscription_count).

Response (200 OK)

json
{
  "batch": [
    {},
    { "user_count": 12 }
  ]
}

3. Get Active Sockets Count

Retrieve the total count of active WebSocket connections for your application.

http
GET /apps/:id/sockets

Response (200 OK)

json
{
  "sockets": 142
}

4. List Occupied Channels

Retrieve a list of currently active channels that have at least one subscriber.

http
GET /apps/:id/channels

Query Parameters

ParameterTypeRequiredDescription
filter_by_prefixstringNoFilter channels starting with a prefix (e.g. presence- or private-).
infostringNoAdditional metadata attributes (user_count). Requires filter_by_prefix=presence-.

Response (200 OK)

json
{
  "channels": {
    "presence-room-1": { "user_count": 3 },
    "presence-room-2": { "user_count": 1 },
    "public-feed": {}
  }
}

5. Get Channel Info

Retrieve occupancy and subscriber metadata for a single channel.

http
GET /apps/:id/channels/:channel_name

Query Parameters

ParameterTypeRequiredDescription
infostringNoComma-separated attributes: user_count (presence channels only) or subscription_count (non-presence channels).

Response (200 OK)

json
{
  "occupied": true,
  "user_count": 5
}

If the channel currently has no active subscribers:

json
{
  "occupied": false
}

6. Get Presence Channel Users

Retrieve a list of all user IDs currently online in a specific presence channel.

http
GET /apps/:id/channels/:channel_name/users

Note: Only valid for channels prefixed with presence-.

Response (200 OK)

json
{
  "users": [
    { "id": "user_101" },
    { "id": "user_102" },
    { "id": "user_103" }
  ]
}

7. Terminate User Connections

Forcefully disconnect and terminate all active WebSocket connections belonging to a specific user_id.

http
POST /apps/:id/users/:user_id/terminate_connections

Response (200 OK)

json
{}

Terminated connections receive a WebSocket close frame with code 4200.


8. Send Event to User

Send an event directly to all active WebSocket connections belonging to an authenticated user_id.

Socketo delivers the event with wire channel #server-to-user-<user_id>, which automatically triggers callbacks registered via pusher.user.bind(eventName, callback) in the official pusher-js SDK.

You can also trigger user events using the official Pusher backend SDK method pusher.sendToUser(userId, name, data).

http
POST /apps/:id/users/:user_id/events

Request Body

json
{
  "name": "notification",
  "data": {
    "title": "New Alert",
    "message": "You have a new update."
  }
}

Response (200 OK)

json
{}

Error Status Codes

HTTP CodeDescription
400 Bad RequestMissing required fields, invalid JSON, or invalid info attribute query.
401 UnauthorizedInvalid HMAC signature, missing auth query parameters, or timestamp expired (> 600s).
403 ForbiddenApplication is disabled or suspended.
404 Not FoundApplication ID not found or non-existent endpoint.
429 Too Many RequestsEdge rate limit exceeded.