Please be aware that you are viewing our bleeding edge unstable documentation. Unless you wanted to view the bleeding edge (and possibly unstable) documentation, we recommend you use our stable docs.

Go to Ably's stable canonical documentation »

I know what I'm doing, let me see the bleeding edge docs »

You are viewing our bleeding edge unstable documentation. We recommend you use our stable documentation »
Fork me on GitHub

REST API Specification

The Ably REST API provides a way for a wide range of server and client devices to communicate with the Ably service over REST. The REST API does not provide a realtime long-lived connection to Ably, but in all other respects is a simple subset of the full realtime messaging API.

The primary use-case for the REST API is for servers that are part of the back-end of an application such as a web application, that publish messages, issue access tokens (temporary and client-specific) for its various clients, obtain message and presence history and retrieve statistics.

The functional scope of the REST API includes:

Whilst use of our REST API directly is fully supported, we instead recommend that customers should use our Ably REST client libraries that support a range of platforms including Javascript, iOS, Android, Java, Python Ruby, .NET, Go, etc. The client libraries are well documented and provide additional features that improve performance and resilience that the REST API cannot deliver on its own, such as automatic re-routing around network problems by using alternative data centers.

Common API behavior

General

The REST API defaults to returning results, and expects request bodies, in JSON format. An Accept header is used to specify a specific response format – JSON or an alternative – and the following formats are allowed:

It is also possible to specify the response format with the format query parameter (with supported values being json, jsonp, msgpack, html). Any Accept header takes precedence over a format parameter.

Similarly, POST requests may contain a request body in JSON or other formats as indicated by a Content-Type header. The supported content types are:

Specific request and response data types are documented in the context of each API or route.

A response status code of 20X (200, 201 or 204) indicates success. A successful result will typically provide a response body but certain operations (such as DELETE) may respond with a 204 response and no response body.

All other standard HTTP statusCodes signify an error. Errors from all APIs are returned as an object of the form:

{
  error: {
    code: <ably error code>,
    message: <string>,
    statusCode: <http status code>
  }
}

Additionally, when you may not have access to the response body due to limitations of your HTTP client, we include the following custom Ably headers to work around that problem:

X-Ably-ErrorCode: <ably error code, equivalent to error.code>
X-Ably-ErrorMessage: <string, equivalent to error.message>

The properties of an Ably error are:

code
A specific reason code as defined in the public errors definition, where one is known
statusCode
Where a code is not available, the statusCode provides a generic indication of the nature of the failure and maps to standard HTTP statusCodes
message
The message string is an English language string that aims to provide useful information to the developer. It is not necessarily intended to be an informative string for the end user

Wherever possible, success response bodies contain links, in HATEOS style, to other resources relevant to the response; where these are present these are included as href attributes on the applicable part of the response object.

GET, PUT, POST and DELETE are available in all contexts where they make sense. GET is always idempotent.

Versioning

By default, all requests receive the latest version of the API, which is currently 1.0.

When we make backwards-incompatible API changes to the API, we release new versions. Therefore, we encourage you to explicitly request the version you are interfacing with in all requests using one of the following mechanisms:

1. Include a X-Ably-Version header. Example:

curl https://rest.ably.io/time \
 -H "X-Ably-Version: 1.0"

2. Include the version query string param v. Example:

curl https://rest.ably.io/time?v=1.0

Pagination

REST APIs whose responses may have unbounded size have paginated responses; that is, if a full response to the query could exceed a limit (a default or a limit given as a parameter to the call) the first response contains a subset of the results, and further “pages” of the result are available on subsequent requests. Each response (the initial response and responses to each subsequent request) is accompanied by one or more relative links relating to the current query.

Responses contain one or more of the following relative links:

first
a link to the first page of results for this query. This link also makes the query repeatable; any params that are resolved at query time (for example default values for omitted time-related params) have their resolved values included explicitly in the first link.
current
a stable link to the current page of results.
next
on each page except the last in a paginated result, the next link is a link to the next page of results.

Relative links are presented by default as an RFC 5988 Link HTTP response header; there is a separate Link header for each relative link accompanying the response. The rel types used are first, next and current as specified in the RFC.

A Link header has the format:

Link: <{url}>; rel="{rel}"

where {url} is the URL of the link and {rel} is the relation type.

For example:

Link: <./stats?start=1380794880000&end=1380794881058&limit=100&unit=minute&direction=forwards
&format=json&first_start=1380794880000>; rel="first"

In principle the link URL might be any valid URL but in practice it will always be a relative URL, and it must be interpreted relative to the original query URL. Clients should treat link URLs opaquely; in particular, params (such as first_start in the example above) may be undocumented and unsupported except where a client uses the link URL in its entirety.

Clients that are unable to process response headers may also request an envelope response type.

Control of response content

By default the response body of a query response will contain the requested resource, encoded in the requested format. However, there are also query params that allow the response body to be adjusted to contain only a subset of the representation, or a restructured representation.

The following params are supported:

fields

Specifying ?fields=<field spec>[,<field spec>, ...] returns the representation containing only the specified fields. A field spec is a specifier which is either a single field – in which case the representation contains only that fields’s value – or a dot-separated sequence of fields, in which case the representation contains only the fields matching those given in the field spec at each level in the hierarchy.

Example
curl https://rest.ably.io/stats?fields=channels.peak,intervalId \
     -u "{{API_KEY}}"

# Response
[{
    "channels": { "peak": 2 },
    "intervalId": "2015-11-20:15"
}]

flatten

Specifying ?flatten=true will result in a flattened representation, with the returned object structure being flattened into one with a single level of long keys instead of a deep structure. When the results contain array elements, the array index of each element is included as the corresponding component of the result key.

Example
curl https://rest.ably.io/stats?flatten=true&fields=channels.peak,intervalId \
     -u "{{API_KEY}}"

# Response
{
    "0.channels.peak": 2,
    "0.intervalId": "2015-11-20:15"
}

select

Specifying ?select=<path spec> returns a representation of the resource containing only the fields that match the given path specification. Like the fields param this permits only specific fields to be obtained, but the path spec may contain wildcard elements, and all matching fields in the representation are returned.

The result is a partially-flattened representation, as a map whose keys are the long keys that match the path spec, and the values are the corresponding values. When the results contain array elements, the array index of each element is included as the corresponding component of the result key.

Example
curl https://rest.ably.io/stats?select=*.channels.* \
     -u "{{API_KEY}}"

# Response
[{
    "0.channels.peak": 5,
    "0.channels.min": 1,
    "0.channels.mean": 3,
    "0.channels.opened": 2
}]

Envelope response format

A client that is unable to access response headers or status code can request an envelope response that contains the usual response, plus Link header information and the response status code wrapped in an object as a single response body. This is useful for JSONP and may be useful in other environments. Envelope responses are only supported for JSON, JSONP and HTML formats.

A client requests an envelope response by including an envelope=<format> param in the request.

A JSON envelope response body response for a request with an envelope=json param has the format:

{
    "statusCode": <status code>,
    "response": <result of API call>,
    "rel": {
        "first": <URL>,
        ...
    }
}

where the response member references the API result in the usual format. The rel member, present only in paginated responses, includes each of the rel links associated with the response.

Envelope responses always are always made with a 200 status code; the status of the API request itself must be obtained from the statusCode member of the response body.

Authentication

To understand the REST API it is easiest first to understand the various authentication methods that Ably supports. For a detailed explanation, view the Authentication documentation.

Clients can access Ably, whether using REST or the Realtime service, by two methods, explained briefly below:

Basic Authentication

Using one of the application keys created via the application dashboard, basic authentication provides the simplest method to authenticate with Ably, but has two important limitations:

Usage in HTTP request header

Authorization: Basic <Base64-encoded key>

where <Base64-encoded key> is the full application key string obtained through the dashboard, encoded with RFC 4648 Base64.

Example request:

curl https://rest.ably.io/channels/rest-example/messages \
 --header "Authorization: Basic {{API_KEY_BASE64}}"

When using a generic HTTP client library that accepts separate username and password arguments for an HTTP request, the application key can be split at the first colon, with the initial segment being used as the username, and the remaining string (without the leading colon) used as the password.

Example request:

curl https://rest.ably.io/channels/rest-example/messages \
 --user "{{API_KEY}}"

Token Authentication

Using a token obtained via the REST API requestToken endpoint, tokens provide a means to authenticate with Ably without sharing a private API key. Tokens have a short lifetime and therefore they may more readily be distributed to clients where there is a risk of compromise. Tokens may also be issued with a particular scope – such as a limited set of access rights or capabilities or being limited to use by a specific clientId identity – and therefore token-based authentication provides the flexibility to implement trusted identities and access control policies in the application. See Authentication for more details.

The requestToken endpoint may be used without explicit authentication, relying on the implicit authentication of submitting a validly signed token request.

Usage in HTTP request header

Authorization: Bearer <Base64-encoded token string>

The <Base64-encoded token string> is the token attribute of the token generated by requestToken, encoded with RFC 4648 Base64. If using a generic HTTP client library it will probably be necessary to add the Authorization header explicitly.

Example request:

curl https://rest.ably.io/channels/rest-example/messages \
 --header "Authorization: Bearer {{TOKEN_BASE64}}"

API routes

Channel routes

Routes providing access to the messaging service within a channel scope.

Publish one or more messages on a channel

POST rest.ably.io/channels/<channel id>/messages

Publish a message on a channel. Note that since the REST API is stateless, publication using this API is outside the context of any specific connection.

The request body contains message details and is an object of the form:

{
  name: <event name>,
  data: <message payload>,
  encoding: <optional encoding>,
  clientId: <optional explicit client identifier>,
  connectionKey: <optional private connection key>,
  extras: <optional, see below>
}

In JSON format, the accepted types for the data payload are:

MessagePack additionally supports byte arrays

A message may be published over REST on behalf of an existing realtime connection when a valid connectionKey is present. For example, if you want to publish a message using the REST API so that it appears to come from an existing connected realtime client, then the connection’s private (secret) connection key must be included. See a publish on behalf of a realtime client example.

Example request:

curl -X POST https://rest.ably.io/channels/rest-example/messages \
 -u "{{API_KEY}}" \
 -H "Content-Type: application/json" \
 --data '{ "name": "publish", "data": "example" }'
Message extras

Messages can include an optional extras field, used by extensions to Ably’s core realtime service.

Send push notification

You can send a push notification to devices subscribed to the channel the message is sent to by setting the @push@ field in the extras object, like this:

{
  <... message fields ...>
  extras: {
    push: {
      data: <arbitrary key-value string-to-string payload>,
      notification: {
        title: <string, title to display at the notification>,
        body: <string, text below title on the expanded notification>,
        icon: <string, platform-specific>,
        sound: <string, platform-specific>,
        collapseKey: <string, platform-specific, used to group notifications together>
      }
      apns: <optional, extends and overrides generic values when delivering via APNs>,
      fcm: <optional, extends and overrides generic values when delivering via GCM/FCM>,
      web: <optional, extends and overrides generic values when delivering via web>
    }
  }
}

For each underlying transport service (like APNs, FCM/GCM, etc.) an object can be provided with the same shape as the parent object, plus any transport-specific field you may want to add (e. g. content-available for APNs).

Full example of a request publishing a message with a push payload:

curl -X POST https://rest.ably.io/channels/push-enabled:rest-example/messages \
 -u "{{API_KEY}}" \
 -H "Content-Type: application/json" \
 --data \
 '
{
  "name": "some event name for realtime receivers",
  "data": "example non-push data for realtime receivers",
  "extras": {
    "push": {
      "notification": {
        "title": "Hello from Ably!",
        "body": "Example push notification from Ably."
      },
      "data": {
        "foo": "bar",
        "baz": "qux"
      },
      "apns": {
        "notification": {
          "content-available": 1
          "sound": "ably-ios.wav"
        }
      }
    }
  }
}
'
Parameters

None

Options
Content-Type
application/json, application/x-msgpack or application/x-www-form-urlencoded
Accept
not applicable
Auth required
yes (basic or token)
Returns

Nothing when successful, else returns an error.

Retrieve message history for a channel

GET rest.ably.io/channels/<channel id>/messages

If a channel is configured to persist messages, then all messages on that channel, within your account retention period, are available via this API endpoint. If persistence is not configured, then there are no guarantees as to how many historical messages will be available for the channel. Find out more about message persistence.

Example request:

curl https://rest.ably.io/channels/rest-example/messages \
 -u "{{API_KEY}}"
Parameters
start
beginning of time The start of the query interval as a time in milliseconds since the epoch. A message qualifies as a member of the result set if it was received at or after this time.
end
now The end of the query interval as a time in milliseconds since the epoch. A message qualifies as a member of the result set if it was received at or before this time.
limit
100 The maximum number of records to return. A limit greater than 1,000 is invalid.
direction
backwards The direction of this query. The direction determines the order of the returned result array, but also determines which end of the query interval is the start point for the search. For example, a forwards query uses start as the start point, whereas a backwards query uses end as the start point.
Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token)
Returns

In each case a successful result is a paginated response with an array containing the items that match the query (and it may be empty).

[{
  id: <unique message id>
  name: <event name>,
  data: <message payload>,
  timestamp: <message timestamp in ms since epoch>
}]

Retrieve instantaneous presence status for a channel

GET rest.ably.io/channels/<channel id>/presence

Obtain the set of members currently present for a channel.

Example request:

curl https://rest.ably.io/channels/rest-example/presence \
 -u "{{API_KEY}}"
Parameters
clientId
optional filter to restrict members present with that clientId
connectionId
optional filter to restrict members present with that connectionId
limit
100 The maximum number of records to return. A limit greater than 1,000 is invalid.
Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token)
Returns

A successful request returns a paginated response with an array containing the members that are currently present on the given channel. If there are no members present, an empty collection is returned.

[{
  id: <a unique member identifer generated by Ably>,
  clientId: <member client id provided by the client>,
  connectionId: <a unique connection id generated by Ably>
  timestamp: <message timestamp in ms since epoch>
  action: <presence state>,
  data: <optional clientData provided by the client>
}]

Retrieve presence state history for a channel

GET rest.ably.io/channels/<channel id>/presence/history

Obtain the history of presence messages for a channel.

Example request:

curl https://rest.ably.io/channels/rest-example/presence/history \
 -u "{{API_KEY}}"
Parameters
start
beginning of time The start of the query interval as a time in milliseconds since the epoch. A message qualifies as a member of the result set if it was received at or after this time.
end
now The end of the query interval as a time in milliseconds since the epoch. A message qualifies as a member of the result set if it was received at or before this time.
limit
100 The maximum number of records to return. A limit greater than 1,000 is invalid.
direction
backwards The direction of this query. The direction determines the order of the returned result array, but also determines which end of the query interval is the start point for the search. For example, a forwards query uses start as the start point, whereas a backwards query uses end as the start point.
Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token)
Returns

A successful request returns a paginated response with an array containing the members that are currently present on the given channel. If there are no members present, an empty collection is returned.

[{
  id: <a unique member identifer generated by Ably>,
  clientId: <member client id provided by the client>,
  connectionId: <a unique connection id generated by Ably>
  timestamp: <message timestamp in ms since epoch>
  action: <presence state>,
  data: <optional clientData provided by the client>
}]

Push

Register a device for receiving push notifications

Register a device’s details, including the information necessary to deliver push notifications to it.

POST rest.ably.io/push/deviceRegistrations

The request body contains device and push recipient details, and is an object of the form:

{
  id: <string>,
  clientId: <optional, string, client identifier to associate with registration>,
  platform: <string, one of ios, android or browser>,
  formFactor: <string, one of phone, tablet, desktop, tv, watch, car or embedded>,
  metadata: <optional, object, with flexible key/value string pairs>,
  push: {
    recipient: {
      transportType: <string, one of gcm, fcm, apns or web>,
      <additional key/value string pairs for transport-specific recipient address>
    }
  }
}

The recipient address attributes are necessary and vary by underlying transport service.

For APNs:

{
  deviceToken: <string>
}

For GCM/FCM:

{
  registrationToken: <string>
}

For web:

{
  targetUrl: <string>
  encryptionKey: <string>
}

Example request:

curl -X POST https://rest.ably.io/push/deviceRegistrations \
 -u "{{API_KEY}}"
 -H "Content-Type: application/json" \
 --data \
'{
  "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
  "platform": "ios",
  "formFactor": "phone",
  "push": {
    "recipient": {
      "transportType": "apns",
      "deviceToken": "740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad"
    }
  }
}'
Parameters

None

Options
Content-Type
application/json, application/x-msgpack or application/x-www-form-urlencoded
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-subscribe or push-admin capability; when registering for a client ID with a push-subscribe capability, the token must be associated with that client ID)

A successful request returns the just-registered device details. It includes an updateToken, which is a token that can be used by typically a mobile device to authenticate with Ably later and update an existing device registration (for example, for updating a GCM or FCM registration token).

An unsuccessful request returns an error.

Update a device registration

Device registrations can be either upserted (the existing registration is replaced entirely) with a PUT operation, or specific attributes of an existing registration can be updated using a PATCH operation:

PUT rest.ably.io/push/deviceRegistrations/<device id>

The body must have the same shape as when registering the device. The PUT operation will replace the existing device registration, however please bear in mind that a registered device in Ably is largely immutable. As such, only the following attributes are currently updatable and any attempt to modify other fields will result in the update failing:

Additionally, if the push.state or updateToken attributes are provided, they will be accepted if they match the existing value. However if they differ (and are not null or omitted), then the update will fail.

If you need to make changes to any other fields, you will have to deregister the existing device and then register a new one.

Example request:

curl -X PUT https://rest.ably.io/push/deviceRegistrations/01ARZ3NDEKTSV4RRFFQ69G5FAV \
 -u "{{API_KEY}}"
 -H "Content-Type: application/json" \
 --data \
'{
  "id": "01ARZ3NDEKTSV4RRFFQ69G5FAV",
  "platform": "ios",
  "formFactor": "phone",
  "metadata": {
    "timezone": "PST"
  },
  "push": {
    "recipient": {
      "transportType": "apns",
      "deviceToken": "740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad"
    }
  }
}'
Parameters

None

Options
Content-Type
application/json, application/x-msgpack or application/x-www-form-urlencoded
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability)

A successful request returns the updated device details.

An unsuccessful request returns an error.

PATCH rest.ably.io/push/deviceRegistrations/<device id>

The body must have the same shape as when registering the device, except only fields to be changed should be provided. Any fields provided replace existing values. Please bear in mind that fields whose values are structured (JSON-like arrays or objects) types will replace existing values as opposed to be merged into existing values. metadata and push.recipient are examples of these types. Currently only the following attributes are currently updatable and any attempt to modify other fields will result in the update failing:

If you need to make changes to any other fields, you will have to deregister the existing device and then register a new one.

Example request:

curl -X PATCH https://rest.ably.io/push/deviceRegistrations/01ARZ3NDEKTSV4RRFFQ69G5FAV \
 -u "{{API_KEY}}"
 -H "Content-Type: application/json" \
 --data \
'{
  "metadata": {
    "myKey": "value"
  }
 }'
Parameters

None

Options
Content-Type
application/json, application/x-msgpack or application/x-www-form-urlencoded
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability, or token authentication using the device’s update token)

A successful request returns the updated device details.

An unsuccessful request returns an error.

Get details from a registered device

GET rest.ably.io/push/deviceRegistrations/<device id>

Obtain the details for a device registered for receiving push registrations.

Example request:

curl https://rest.ably.io/push/deviceRegistrations/01ARZ3NDEKTSV4RRFFQ69G5FAV \
 -u "{{API_KEY}}"
Parameters

None.

Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability)
Returns

A JSON object like:

{
  id: <string>,
  clientId: <optional, string>
  platform: <string>
  formFactor: <string>,
  metadata: <object>,
  updateToken: <string>,
  push: {
    recipient: {
      transportType: <string>,
      <additional recipient address key/value pairs>
    },
    state: <active or failed>
  }
}

or a 404 error if a device by that ID does not exist.

List registered devices

GET rest.ably.io/push/deviceRegistrations

Obtain the details for devices registered for receiving push registrations.

Example request:

curl https://rest.ably.io/push/deviceRegistrations \
 -u "{{API_KEY}}"
Parameters
deviceId
optional filter to restrict to devices associated with that deviceId
clientId
optional filter to restrict to devices associated with that clientId
limit
100 The maximum number of records to return. A limit greater than 1,000 is invalid.
Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability)
Returns

A successful request returns a paginated response of:

[{
  id: <string>,
  clientId: <optional, string>
  platform: <string>
  formFactor: <string>,
  metadata: <object>,
  updateToken: <string>,
  push: {
    recipient: {
      transportType: <string>,
      <additional recipient address key/value pairs>
    },
    state: <active or failed>
  }
}]

Reset a registered device’s update token

POST rest.ably.io/push/deviceRegistrations/<device id>/resetUpdateToken

Example request:

curl -X POST https://rest.ably.io/push/01ARZ3NDEKTSV4RRFFQ69G5FAV/resetUpdateToken \
 -u "{{API_KEY}}"
Parameters

None

Options
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability, or token authentication using the device’s update token)

A successful request returns the updated device details.

A unsuccessful request returns an error.

Unregister a single device for push notifications

DELETE rest.ably.io/push/deviceRegistration/<device id>

Unregisters a single device by its device ID. All its subscriptions for receiving push notifications through channels will also be deleted.

Please note that this operation is done asynchronously so immediate requests subsequent to this delete request may briefly still return the device.

Example request:

curl -X DELETE \
 https://rest.ably.io/push/deviceRegistrations/01ARZ3NDEKTSV4RRFFQ69G5FAV \
 -u "{{API_KEY}}"
Parameters

None

Options
Content-Type
not applicable
Auth required
yes (basic or token with push-admin capability)
Returns

A successful request returns an empty response.

An unsuccessful request returns an error.

Unregister matching devices for push notifications

DELETE rest.ably.io/push/deviceRegistrations

Unregisters devices. All their subscriptions for receiving push notifications through channels will also be deleted.

Please note that this operation is done asynchronously so immediate requests subsequent to this delete request may briefly still return the device.

Example request:

curl -X DELETE \
 https://rest.ably.io/push/deviceRegistrations?deviceId=01ARZ3NDEKTSV4RRFFQ69G5FAV \
 -u "{{API_KEY}}"
Parameters
deviceId
Filter to restrict to subscriptions for that deviceId. Cannot be used with clientId.
clientId
Filter to restrict to subscriptions associated with that clientId. Cannot be used with deviceId.
Options
Content-Type
not applicable
Auth required
yes (basic or token with push-admin capability)
Returns

A successful request returns an empty response.

An unsuccessful request returns an error.

Subscribe to a channel

Subscribe either a single device or all devices associated with a client ID to receive push notifications from messages sent to a channel.

POST rest.ably.io/push/channelSubscriptions

The request body contains subscription details and is an object of the form:

{
  channel: <string>,
  deviceId: <optional, string, must be set when clientId is empty, cannot be used with clientId>,
  clientId: <optional, string, must be set when deviceId is empty, cannot be used with deviceId>
}
curl -X POST https://rest.ably.io/push/channelSubscriptions \
 -u "{{API_KEY}}"
 -H "Content-Type: application/json" \
 --data \
 '
{
  "channel": "rest-example",
  "deviceId": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
}
'
Parameters

None

Options
Content-Type
application/json, application/x-msgpack or application/x-www-form-urlencoded
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-subscribe or push-admin capability; when subscribing for a client ID with a push-subscribe capability, the token must be associated with that client ID)

A successful request returns an empty object.

A unsuccessful request returns an error.

Unsubscribe from push notifications for channels

DELETE rest.ably.io/push/channelSubscriptions

Stop receiving push notifications when push messages are published on the specified channels.

Please note that this operation is done asynchronously so immediate requests subsequent to this delete request may briefly still return the subscription.

Example request:

curl -X DELETE \
 https://rest.ably.io/push/channelSubscriptions?deviceId=01ARZ3NDEKTSV4RRFFQ69G5FAV \
 -u "{{API_KEY}}"
Parameters
channel
string, optional. If not set, all subscriptions on all channels will be deleted.
deviceId
Filter to restrict to subscriptions for that deviceId. Cannot be used with clientId.
clientId
Filter to restrict to subscriptions associated with that clientId. Cannot be used with deviceId.
Options
Content-Type
not applicable
Auth required
yes (basic or token with push-subscribe or push-admincapability; when deleting by client ID with a push-subscribe capability, the token must be associated with that client ID)
Returns

A successful request returns an empty response.

An unsuccessful request returns an error.

List channel subscriptions

GET rest.ably.io/push/channelSubscriptions

Get a list of push notification subscriptions to channels.

Example request:

curl https://rest.ably.io/push/channelSubscriptions \
 -u "{{API_KEY}}"
Parameters
channel
Filter to restrict to subscriptions associated with that channel.
clientId
Filter to restrict to subscriptions associated with that clientId. Cannot be used with deviceId.
deviceId
Filter to restrict to subscriptions for that deviceId. Cannot be used with clientId.
limit
100 The maximum number of records to return. A limit greater than 1,000 is invalid.
Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability)
Returns

A successful request returns a paginated response of:

[{
  channel: <string>,
  clientId: <string, only present when deviceId is not present>
  deviceId: <string, only present when clientId is not present>,
}]

List all channels with at least one subscribed device

GET rest.ably.io/push/channels

Example request:

curl https://rest.ably.io/push/channels \
 -u "{{API_KEY}}"
Parameters

None

Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token with push-admin capability)
Returns

A successful request returns a paginated response of:

[<string, channel name>]

Publish a push notification to a single device

Convenience endpoint to deliver a push notification payload to a single device or set of devices identified by their client identifier.

If you want to send a push notification to multiple devices or use a more flexible publish-subscribe architecture so that you don’t need to know about recipient devices’s details, we recommend you look at registering devices for push, then subscribe them to channels, and then send messages to the channels with push payloads.

This direct publish endpoint is designed for customers who typically have legacy devices they wish to push directly to, or if they want to publish to all devices for a single user.

POST rest.ably.io/push/publish

The request body is an object of the form:

{
  recipient: <object>
  <... rest of the fields just like a normal push-enabled message's extras.push object ...>
}

Example request:

curl -X POST https://rest.ably.io/push/publish \
 -u "{{API_KEY}}" \
 -H "Content-Type: application/json" \
 --data \
 '
{
  "recipient": {
    "clientId": "myClientId"
  },
  "notification": {
    "title": "Hello from Ably!",
    "body": "Example push notification from Ably."
  },
  "data": {
    "foo": "bar",
    "baz": "qux"
  }
}'

The recipient field supports delivering either to devices registered to Ably by device ID, by their associated client ID, or directly to devices using the underlying notifications service (GCM, APNs, etc.), thus bypassing registrations to Ably altogether.

By device ID:

{
  deviceId: <string>
}

By client ID:

{
  clientId: <string>
}

For APNs devices:

{
  transportType: "apns",
  deviceToken: <string>
}

For GCM/FCM devices:

{
  transportType: <fcm, gcm>,
  registrationToken: <string>
}

For web:

{
  transportType: "web",
  targetUrl: <string>,
  encryptionKey: <string>
}

The rest of the fields are normal push-enabled Ably message’s push.extras object.

Parameters

None

Options
Content-Type
application/json, application/x-msgpack or application/x-www-form-urlencoded
Accept
not applicable
Auth required
yes (basic or token with push-admin capability)

A successful request returns an empty response.

An unsuccessful request returns an error.

Authentication

Request an access token

POST rest.ably.io/keys/key id/requestToken

This is the means by which clients obtain access tokens to use the service. The construction of a token request is described in the Authentication token request spec documentation. The resulting token response object contains the token properties as defined in token request spec.

Example request:

curl -X POST "https://rest.ably.io/keys/{{API_KEY_NAME}}/requestToken" \
 -u "{{API_KEY}}" \
 -H "Content-Type: application/json" \
 --data '{ "keyName": "{{API_KEY_NAME}}", "timestamp": {{MS_SINCE_EPOCH}} }'
Parameters

None

Options
Request body
signed or unsigned token request. All token requests require values for keyName and timestamp attributes. In addition, signed token require values for attributes nonce and mac.
Content-Type
text/plain
Accept
application/json by default, or application/x-msgpack
Auth required
no (for signed token requests), yes (for unsigned token requests, basic or token permitted)
Returns

A successful request will return a token details object containing the token string.

{
  "token": "xVLyHw.CLchevH3hF....MDh9ZC_Q", // token string
  "keyName": "xVLyHw.mDYnFA",
  "issued": 1428356667,
  "expires": 1428360267,
  "capability": "{\"*\":[\"*\"]}"
}

Application routes

Routes providing access to the messaging service within an application scope.

Retrieve usage statistics for an application

GET rest.ably.io/stats

Example request:

curl https://rest.ably.io/stats?unit=hour \
 -u "{{API_KEY}}"

The Ably system can be queried to obtain usage statistics for a given application, and results are provided aggregated across all channels in use in the application in the specified period. Stats may be used to track usage against account quotas.

Stats queries are made by specifying a query interval and the granularity expected in the results. The query interval is expressed as a start and end time, each being a timestamp in milliseconds since the epoch. Stats are aggregated by the system in ‘sub-minute’ intervals of 6s (ie 0.1m), so query interval start and end times are rounded down to the nearest sub-minute boundary.

Parameters
start
beginning of time The start of the query interval as a time in milliseconds since the epoch.
end
now The end of the query interval as a time in milliseconds since the epoch.
limit
100 The maximum number of records to return. A limit greater than 1,000 is invalid.
direction
backwards The direction of this query. The direction determines the order of the returned result array, but also determines which end of the query interval is the start point for the search.
unit
minute One of the values minute, hour, day or month, specifying the unit of aggregation in the returned results.
Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
yes (basic or token)
Returns

In each case a successful result is a paginated response with an array containing the items that match the query (and it may be empty).

Stats records contain a hierarchy of elements relating to messages, connections and other resources consumed in an interval. Any single record may contain a subset of the elements, omitting empty sections.

See a complete example of a statistics response.

Utilities

Get the service time

GET rest.ably.io/time

This returns the service time in milliseconds since the epoch. This may be used by clients that do not have local access to a sufficiently accurate time source when generating a token request. (Token requests include a timestamp and have a limited validity period to help defend against replay attacks.)

The result is a JSON-encoded array of length 1 containing the time result as a number.

curl http://rest.ably.io/time
Parameters

None

Options
Content-Type
not applicable
Accept
application/json by default, or application/x-msgpack, text/html
Auth required
no
Returns
[ {{MS_SINCE_EPOCH}} ]

Back to top