Subscribe V2
To successfully subscribe and receive messages, you must send at least two subscribe calls.
- In the first call, set the
tt
parameter to0
. The server responds with thet
(timetoken) andr
(region) parameters. - In subsequent calls, set the
tt
parameter to the value of thet
parameter and thetr
parameter to the value of ther
parameter the server returned in the previous call.
The subscribe call returns messages with timetokens that are more recent than the one passed in the subscribe call. As you continue to make new subscribe calls, you must set the value of tr
to the last received value of r
as it keeps you subscribed to the same data center and prevents you from receiving duplicate messages.
Success Responses
On success, an object is returned. Check the Responses section for more information.
If you are subscribed to a channel group named myCG
, and you receive a message on myCG from a member channel named myCH
, b
will contain "myCG", and c will contain "myCH".
The value of e
denotes the type of messages. If e
is 1
the message is of type Signal
and if e
is 2
the message is of type Objects
. A value of 0
or no e
field means the message is a regular message.
Each time a message action is added or removed, a specially-structured action event message will be published on the same channel as the parent message. These action event messages will come through the same subscribe event loop as the user's regular messages, but the envelope of the message will show an "e" field of 3
. The data of the action event message will show whether the action was added or removed, and the data of the message action in question. The UUID
that caused this event will also be returned in the envelope of the message, in the "i" field.
When subscribing to both channels and channel groups, the corresponding entry for an non-CG member channel will be identical to that of the entry for it element 2.
Error Responses
In the event of an error, you will receive a non-200 HTTP status code. Depending on the error, you may or may not have a parseable array returned.
Common HTTP Status Codes should be expected. In the event of a non-Common HTTP Status Code and/or unparseable JSON, assume an error, fire your error callback with as much information as possible, wait 1 second, and retry the failed request indefinitely.
It is critical to design your subscribe logic to be durable and always retry. Although it should try indefinately, since its calling the error callback on each failure, the developer will be able to unsubscribe from the channel(s) if needed.
Path Parameters |
---|
sub_key string — REQUIREDYour app's subscribe key from Admin Portal. |
channel string — REQUIREDThe channel name(s) you are subscribing to. Verify that channels are comprised of valid characters. You may subscribe to mulitple channels using a comma seperator. If subscribing to no channels (only channel groups), use a comma char (,) as a placeholder. You may subscribe to channels, channels & channel groups, or just channel groups. Example:
|
callback string — REQUIREDThe JSONP callback name to wrap the function in. Use Example (myCallback):
Example (zero):
|
Query Parameters |
---|
tt string0 (zero) for the initial subscribe, or a valid timetoken if resuming / continuing / fast-forwarding from a previous subscribe flow. Example:
|
tr stringRegion as returned from the initial subscribe call (with |
channel-group stringChannel group name(s) to subscribe to. If subscribing to more than one channel group, use a comma separator between channel group names. You may subscribe to channels, channels & channel groups, or just channel groups. Example:
|
state stringThis parameter can be used to set the state. State is an object with root keys associated with each channel you are setting state for. Example:
|
heartbeat integerThis query parameter can be used to set the presence timeout period. Heartbeat is the mechanism used to 'ping' back from the client to the server that the client is still online. Heartbeat has no functional effect on the performance or integrity of the client itself. Its only provided for Presence functionality. The heartbeat is only germane to the Presence service. Default value is 300 |
auth stringIf the channel / channel group is protected by PAM, Example:
|
uuid stringA UTF-8 encoded string of up to 92 characters used to identify the client. Example:
|
filter-expr stringSet filter expression for Subscribe message filtering. Example:
|
signature stringSignature used to verify that the request was signed with the secret key associated with the subscriber key. If Access Manager is enabled, either a valid authorization token or a signature are required. See Access Manager documentation for details on how to compute the signature. |
timestamp integerUnix epoch timestamp used as a nonce for signature computation. Must have no more than ± 60 second offset from NTP. Required if |
Responses | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
200 Success Body (For normal messages) show all 22 linesBody (For messages of type |
Schema — OPTIONAL | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
t object — OPTIONAL
| |||||||||||||
m object[] — OPTIONAL
|
400
Bad Request
Schema — OPTIONAL |
---|
status integer — OPTIONAL |
service string — OPTIONAL |
error boolean — OPTIONAL |
message string — OPTIONAL |
403
Unauthorized access
Schema — OPTIONAL | |
---|---|
message string — OPTIONAL | |
payload object — OPTIONAL
| |
error boolean — OPTIONAL | |
service string — OPTIONAL | |
status integer — OPTIONAL |
413
Request Entity too large (larger than 30 bytes).
Schema — OPTIONAL |
---|
status integer — OPTIONAL |
service string — OPTIONAL |
error boolean — OPTIONAL |
message string — OPTIONAL |
429
Request rate limit exceeded.
Schema — OPTIONAL |
---|
status integer — OPTIONAL |
error boolean — OPTIONAL |
message string — OPTIONAL |