Skip to main content

Websockets

Astro Websocket Gateway

Astro is StreamElements' dedicated websocket gateway. It employs a publish-subscribe (pubsub) pattern to facilitate real-time data updates.

To establish a WebSocket connection, clients should connect to: wss://astro.streamelements.com

Client-to-Server Request

The following parameters are used in a client-to-server request:

ParameterTypeDescription
typestringDefines the type of request. Valid options are subscribe and unsubscribe.
noncestringA unique identifier for the request. Useful for identifying the corresponding response (Optional).
data.topicstringThe topic to which the client wishes to subscribe.
data.tokenstringThe token used to authenticate the request.
data.token_typestringSpecifies the type of token. Valid options are apikey, jwt and oauth.

Here is an example of a client-to-server request:

{
"type": "subscribe",
"nonce": "86ccb2b3-eb8d-4b3c-902d-509c3f5ca88c",
"data": {
"topic": "channel.follow",
"token": "test_token",
"token_type": "jwt"
}
}

Server-to-Client Response

The following parameters are used in a server-to-client response:

ParameterTypeDescription
idstringThe unique identifier of the response.
typestringDefines the type of response. The only valid option is RESPONSE.
noncestringThe nonce of the original request.
errorstringThe error code, if any.
dataobjectThe data contained in the response.

Here is an example of a server-to-client response:

{
"id": "01HB0YE5TR26EH71DVPJ68MA82",
"ts": "2023-09-20T16:43:21Z",
"type": "response",
"nonce": "86ccb2b3-eb8d-4b3c-902d-509c3f5ca88c",
"data": {
"message": "successfully subscribed to topic",
"topic": "channel.follow"
}
}

Server Notifications

Clients can receive notifications from the server. Here is an example:

{
"id": "01HB0YF39XF16HMHCPDYZYJYFK",
"ts": "2023-09-23T12:06:25Z",
"type": "message",
"topic": "astro",
"data": {
"message":"Hello world!"
}
}

Error Codes

The following error codes may be returned in a server-to-client response:

ErrorDescription
err_internal_errorAn internal error occurred.
err_bad_requestThe request was malformed or invalid.
err_unauthorizedThe request lacked valid authentication credentials.
rate_limit_exceededThe rate limit for the API has been exceeded.
invalid_messageThe message was invalid or could not be processed.

Here is an example of a server-to-client response containing an error:

{
"id": "01HB0YE5Y88FXMXXCN4ME7M8A1",
"ts": "2023-09-20T16:43:21Z",
"type": "response",
"nonce": "86ccb2b3-eb8d-4b3c-902d-509c3f5ca88c",
"error": "err_unauthorized",
"data": {
"message": "invalid token"
}
}

Topics

Information on available topics will be released in the near future.