Authorization
field, see RESTful API authentication.If you have already generated an RTM Token on your server, you can use token authentication. You need to put the following information to the x-agora-token
field and the x-agora-uid
field when sending your HTTP request:
The following sample code shows how to implement token authentication in Java:
Request request = new Request.Builder()
...
// Puts your RTM Token to the `x-agora-token` field of the HTTP request.
.addHeader("x-agora-token", "<Your RTM Token>")
// Puts the uid, which generates the RTM token, to the `x-agora-uid` field of the HTTP request.
.addHeader("x-agora-uid", "<Your uid used to generate the RTM Token>")
...
All requests are sent to the host: api.agora.io
.
api.agora.io
fails, refer to Use dual domain names.https://api.agora.io/dev/v2/project/<appid>
<appid>
is the App ID used by your project. All the request URLs and request bodies are case-sensitive./rtm/users/<user_id>/peer_messages
Sends a peer-to-peer message from the server. The user who sends the message does not have to log in to the RTM system.
For each app ID, the maximum combined frequency of the Sends peer-to-peer message API and the Sends channel message API is 500 calls per second.
The following figure shows the process in which the server sends a peer-to-peer message to the Agora RTM SDK.
wait_for_ack
is true
wait_for_ack
is false
This API has the following URL parameters:
Parameter | Type | Description |
---|---|---|
user_id |
String | RTM user ID to send a peer-to-peer message. Must not exceed 64 characters in length and not be an empty string. This parameter supports the following characters:
As a URL parameter, the first character and the last character must not be a space. |
This API has the following query parameters:
Parameter | Type | Description |
---|---|---|
wait_for_ack |
Boolean | (Optional) Whether the API returns the HTTP response after the Agora RTM server receives the ack response from the receiver to indicate that the message is received. The default is false .
|
This API has the following request body parameters:
Parameter | Type | Description |
---|---|---|
destination |
String | RTM user ID to receive a peer-to-peer message. Must not exceed 64 characters in length and not be an empty string. This parameter supports the following characters:
|
enable_offline_messaging |
Boolean | The offline message feature is deprecated since RTM SDK v1.5.0 for all platforms. In previous versions, users who integrate this feature can still use it. (Optional) Whether to enable offline messages. The default is false .
|
enable_historical_messaging |
Boolean | Whether to save as a historical message. The default value is false .
|
payload |
String | Content of the peer-to-peer message. Must not be an empty string and not exceed 32 KB in length. |
This API has the following response body parameters:
Parameter | Type | Description |
---|---|---|
result |
String | Request result.
|
request_id |
String | Unique ID to identify this request. |
code |
String | Message status.
|
Request URL:
https://api.agora.io/dev/v2/project/876922cbca0098dff4323566daa89675/rtm/users/userA/peer_messages?wait_for_ack=true
Content-type
is application/json;charset=utf-8
Authorization
is basic HTTP or token. See RESTful API Authentication.
Request body:
{
"destination": "userB",
"enable_offline_messaging": false,
"enable_historical_messaging": false,
"payload": "Hello"
}
The message has been sent:
{
"result": "success",
"request_id": "123",
"code": "message_sent"
}
The message has been received:
{
"result": "success",
"request_id": "123",
"code": "message_delivered"
}
The receiver is offline:
{
"request_id": "123",
"code": "message_offline"
}
/rtm/users/<user_id>/channel_messages
Sends a channel message from the server. The user who sends the message does not have to join the channel.
For each app ID, the maximum combined frequency of the Sends peer-to-peer message API and the Sends channel message API is 500 calls per second.
This API has the following URL parameters:
Parameter | Type | Description |
---|---|---|
user_id |
String | RTM user ID to send a channel message. Must not exceed 64 characters in length and not be an empty string. This parameter supports the following characters:
As a URL parameter, the first character and the last character must not be a space. |
This API has the following request body parameters:
Parameter | Type | Description |
---|---|---|
channel_name |
String | RTM channel name to receive a channel message. Must not exceed 64 characters in length and not be an empty string. This parameter supports the following characters:
|
payload |
String | Content of the channel message. Must not be an empty string and not exceed 32 KB in length. |
This API has the following response body parameters:
Parameter | Type | Description |
---|---|---|
code |
String | Message status. "message_sent" : The message is sent. |
request_id |
String | Unique ID to identify this request. |
result |
String | Request result.
|
Request URL
https://api.agora.io/dev/v2/project/876922cbca0098dff4323566daa89675/rtm/users/userA/channel_messages
Content-type
is application/json;charset=utf-8
Authorization
is basic HTTP or token. See RESTful API Authentication.
Request body:
{
"channel_name":"channelA",
"enable_historical_messaging": false,
"payload": "Hello"
}
{
"code": "message_sent",
"request_id": "123",
"result": "success"
}
Status code | Description |
---|---|
200 | The request is successful. |
400 | The request parameters are incorrect. Please check the parameters per the error message. |
401 | User authentication error. |
408 | No response from the server or the request times out. Please try again later. |
429 | Too many requests. |
500 | Internal server error. |