Skip to main content

Get message history

Get message history

GET
https://api.sd-rtn.com/rtm/v2/history/{:appId}/userId/{:userId}/channelType/{:channelType}/channel/{:channelName}

Retrieves historical messages from the specified channel.

Request

Path parameters

appId stringrequired

The App ID of your Agora project.

userId stringrequired

The user ID for the operation.

  • 26 lowercase English letters: a–z
  • 26 uppercase English letters: A–Z
  • 10 numbers: 0–9
  • Space
  • Special characters: !, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _, {, }, |, ~
Caution

Character length must be between 1 and 64.

channelType stringrequired

The type of channel to retrieve messages from.

  • message: Message channel
  • user: User channel
channelName stringrequired

The name of the channel.

  • 26 lowercase English letters: a–z
  • 26 uppercase English letters: A–Z
  • 10 numbers: 0–9
  • Space
  • Special characters: !, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _, {, }, |, ~
Caution

Character length must be between 1 and 64.

start longnullable

The start timestamp of the historical message query. Defaults to 0 if not specified.

end longnullable

The end timestamp of the historical message query. Defaults to 0 if not specified.

messageCount intnullable

The maximum number of messages to return in a single query. The value must be in the range (0, 100]. Defaults to 100 if not specified.

Response

  • If the returned status code is 200, the request was successful. The response body contains the result of the request.

    OK
    • errorCode number

      The status code of the request. A value of 200 indicates success.

    • error boolean

      Indicates whether the request failed.

      • false: The request succeeded.
      • true: The request failed.
    • requestId string

      The unique ID associated with the request.

    • operation string

      The specific operation performed by the request.

    • reason string

      A short explanation of the reason for the error.

    • timestamp number

      The time the request was sent, represented as a Unix timestamp in milliseconds.

    • data object

      The response payload. Contains the following fields:

        • messageList object

          An array of message objects. Each object includes:

            • messageType string

              The type of message content:

              • STRING: Use the message field directly.
              • BINARY: The message is base64-encoded in the message field.
            • message string

              The content of the message.

            • customType string

              The custom message type.

            • publisher string

              The user ID of the message sender.

            • timestamp number

              The time the message was sent, as a Unix timestamp.

        • count number

          The total number of messages retrieved.

        • newStart number

          The start timestamp for the next batch of messages.

  • If the returned status code is not 200, the request failed. The response body includes the error code and description. Refer to status codes to understand the possible reasons for failure.

Authorization

This endpoint requires Basic Auth.

Request example


_2
curl -L 'https://api.sd-rtn.com/rtm/v2/history/{appId}/userId/Tony/channelType/message/channel/chatroom?start=17809876 & end = 1781000 & messageCount = 100' \
_2
-H 'Accept: application/json'

Response example


_28
{
_28
"errorCode": 200,
_28
"error": false,
_28
"requestId": "1121_1234231",
_28
"operation": "getMessage",
_28
"reason": "",
_28
"timestamp": 1234567,
_28
"data": {
_28
"messageList": [
_28
{
_28
"messageType": "STRING",
_28
"message": "Hello, how are you?",
_28
"customType": "text",
_28
"publisher": "Tony",
_28
"timestamp": 1234567890
_28
},
_28
{
_28
"messageType": "BINARY",
_28
"message": "SGVsbG8gV29ybGQ=",
_28
"customType": "image",
_28
"publisher": "Alice",
_28
"timestamp": 1234567891
_28
}
_28
],
_28
"count": 2,
_28
"newStart": 1234567892
_28
}
_28
}