Request an access token
This is the means by which clients obtain access tokens to use the service. You can see how to construct an Ably TokenRequest in the Ably TokenRequest spec documentation, although we recommend you use an Ably SDK rather to create a TokenRequest, as the construction of a TokenRequest is complex. The resulting token response object contains the token properties as defined in Ably TokenRequest spec. Authentication is not required if using a Signed TokenRequest.
Path parameters
-
The key name comprises of the app ID and key ID of an API key.
POST
/keys/{keyName}/requestToken
curl \
-X POST https://rest.ably.io/keys/{keyName}/requestToken \
-H "Content-Type: application/json" \
-d '{"keyName":"YourKey.Name","timestamp":"1559124196551","capability":{"channel1":["publish","subscribe"],"wildcard:channels:*":["publish"]}}'
Request example
{
"keyName": "YourKey.Name",
"timestamp": "1559124196551",
"capability": {
"channel1": [
"publish",
"subscribe"
],
"wildcard:channels:*": [
"publish"
]
}
}
Request examples
Object-1
{
"keyName": "xVLyHw.LMJZxw",
"capability": {
"channel1": [
"publish",
"subscribe"
]
},
"clientId": "string",
"timestamp": 42,
"nonce": "string"
}
{
"keyName": "xVLyHw.LMJZxw",
"capability": {
"channel1": [
"publish",
"subscribe"
]
},
"clientId": "string",
"timestamp": 42,
"nonce": "string",
"mac": "string"
}
Response examples (2XX)
{
"token": "string",
"keyName": "string",
"issued": 42,
"expires": 42,
"capability": "string"
}
Response examples (2XX)
{
"token": "string",
"keyName": "string",
"issued": 42,
"expires": 42,
"capability": "string"
}
Response examples (default)
# Headers
x-ably-errorcode: 42
x-ably-errormessage: string
x-ably-serverid: string
# Payload
{
"message": "string",
"code": 42,
"statusCode": 42,
"href": "string",
"serverId": "string"
}
Response examples (default)
# Headers
x-ably-errorcode: 42
x-ably-errormessage: string
x-ably-serverid: string
# Payload
{
"message": "string",
"code": 42,
"statusCode": 42,
"href": "string",
"serverId": "string"
}