Skip to main content

You are viewing Agora Docs forBeta products and features. Switch to Docs

You are looking at Signaling v1.x Docs. The newest version is  Signaling 2.x

Messaging REST API

You use this API to send messages to a user or a channel.

Authentication

For basic HTTP authentication, you can send peer-to-peer or channel messages with any user ID. For token authentication, you send peer-to-peer or channel messages with only the user ID used to generate the Signaling token.

If the messaging time delay from the server to the client must be less than 200 ms, Agora recommends that you use the Signaling SDK for Linux C++ or the Signaling SDK for Linux Java to send messages from the server to the client.

Basic authentication

You need to pass the basic HTTP authentication and put api_key:api_secret in the Authorization field of the HTTP header. For more information on how to generate the Authorization field, see Secure authentication with tokens.

Token authentication

If you have already generated an Signaling 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 Signaling Token generated at your server.
  • The uid you used to generate the Signaling Token.

Sample code

The following sample code shows how to implement token authentication in Java:


_7
Request request = new Request.Builder()
_7
...
_7
// Puts your Signaling Token to the `x-agora-token` field of the HTTP request.
_7
.addHeader("x-agora-token", "<Your Signaling Token>")
_7
// Puts the uid, which generates the Signaling token, to the `x-agora-uid` field of the HTTP request.
_7
.addHeader("x-agora-uid", "<Your uid used to generate the Signaling Token>")
_7
...

For more information about how to generate an Signaling Token, see Secure authentication with tokens.

Data format

All requests are sent to the host: api.agora.io.

  • Request: See the examples in the following APIs.
  • Response: The response content is in JSON format.
  • Base URL: 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.

Sends peer-to-peer message API (POST)

  • Method: POST
  • Access point: /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 into Signaling.

Call limit

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.

Call sequence

The following figure shows the process in which the server sends a peer-to-peer message to the Signaling SDK.

  • The receiver is online and wait_for_ack is true

  • wait_for_ack is false

Parameters

URL parameters

This API has the following URL parameters:

ParameterTypeDescription
user_idStringSignaling 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:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • The space character. (Not recommended: If the user ID contains a space, then the user ID cannot communicate with the Signaling SDK)
  • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " , ", "|", "~", ",", "'"
As a URL parameter, the first character and the last character must not be a space.

Query parameters

This API has the following query parameters:

ParameterTypeDescription
wait_for_ackBoolean(Optional) Whether the API returns the HTTP response after the Signaling receives the ack response from the receiver to indicate that the message is received. The default is false.
  • true: The API returns the HTTP response after Signaling receives the ack response from the receiver to indicate that the message is received. The HTTP response contains "message delivered" if successful.
  • false: The API returns the HTTP response immediately after Signaling receives the message. The HTTP response contains "message sent" if successful.

Request body parameters

This API has the following request body parameters:

ParameterTypeDescription
destinationStringSignaling 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:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • The space character. (Not recommended: If the user ID contains a space, then the user ID cannot communicate with the Signaling SDK)
  • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " , ", "|", "~", ",", "'"
enable_offline_messagingBoolean
The offline message feature will be deprecated. Agora recommends that you do not use it.
(Optional) Whether to enable offline messages. The default is false.
  • true: Enable offline messages. If the receiver is offline when you send a peer-to-peer message, Signaling saves the message. The receiver will receive the message when online.Signaling saves a maximum of 200 offline messages for each receiver. When the number of saved offline messages exceeds the maximum limit, the latest message replaces the earliest message.
  • false: Disable offline messages.
enable_historical_messagingBooleanWhether to save as a historical message. The default value is false.
  • true: Save as historical messages. You can use the historical message RESTful API to query historical messages.
  • false:Do not save as historical messages.
payloadStringContent of the peer-to-peer message. Must not be an empty string and not exceed 32 KB in length.

Response body parameters

This API has the following response body parameters:

ParameterTypeDescription
resultStringRequest result.
  • "success": The request succeeds.
  • "failed": The request fails.
request_idStringUnique ID to identify this request.
codeStringMessage status.
  • "message_sent": The message is sent.
  • "message_delivered": The message is received.
  • "message_offline": The receiver is offline.

Request example

  • Request URL:


    _1
    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:


_6
{
_6
"destination": "userB",
_6
"enable_offline_messaging": false,
_6
"enable_historical_messaging": false,
_6
"payload": "Hello"
_6
}

Response example

The message has been sent:


_5
{
_5
"result": "success",
_5
"request_id": "123",
_5
"code": "message_sent"
_5
}

The message has been received:


_5
{
_5
"result": "success",
_5
"request_id": "123",
_5
"code": "message_delivered"
_5
}

The receiver is offline:


_4
{
_4
"request_id": "123",
_4
"code": "message_offline"
_4
}

Sends channel message API (POST)

  • Method: POST
  • Access point: /rtm/users/<user_id>/channel_messages

Sends a channel message from the server. You can send a message to a channel without having to join it first.

Call limit

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.

Parameters

URL parameters

This API has the following URL parameters:

ParameterTypeDescription
user_idStringSignaling 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:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • The space character. (Not recommended: If the user ID contains a space, then the user ID cannot communicate with the Signaling SDK)
  • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " , ", "|", "~", ",", "'"
As a URL parameter, the first character and the last character must not be a space.

Request body parameters

This API has the following request body parameters:

ParameterTypeDescription
channel_nameStringSignaling 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:
  • All lowercase English letters: a to z.
  • All uppercase English letters: A to Z.
  • All numeric characters: 0 to 9.
  • The space character. (Not recommended: If the channel name contains a space, then the API cannot communicate with the Signaling SDK)
  • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " , ", "|", "~", ",", "'"
payloadStringContent of the channel message. Must not be an empty string and not exceed 32 KB in length.

Response body parameters

This API has the following response body parameters:

ParameterTypeDescription
codeStringMessage status.
  • "message_sent": The message is sent.
  • request_idStringUnique ID to identify this request.
    resultStringRequest result.
    • "success": The request succeeds.
    • "failed": The request fails.

    Request example

    • Request URL


      _1
      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 Secure authentication with tokens.

    • Request body:


      _5
      {
      _5
      "channel_name":"channelA",
      _5
      "enable_historical_messaging": false,
      _5
      "payload": "Hello"
      _5
      }

    Response example


    _5
    {
    _5
    "code": "message_sent",
    _5
    "request_id": "123",
    _5
    "result": "success"
    _5
    }

    Status code

    Status codeDescription
    200The request is successful.
    400The request parameters are incorrect. Please check the parameters per the error message.
    401User authentication error.
    408No response from the server or the request times out. Please try again later.
    429Too many requests.
    500Internal server error.

    Signaling