logo
In-app Chat
Powered Byspreading
On this page

Query messages


Description

This API allows you to query multiple messages in a specific conversation (group conversation, one-to-one conversation).

API Prototype

  • Request method: POST

  • Request URL: https://zim-api.zego.im/?Action=QueryMessagesByMsgSeq

  • Protocol: HTTPS

  • QPS limit: 20 messages per second

    Warning

    The frequency limit of this API is 20 messages per second, not 20 requests per second.

Request Parameters

The following table describes only the operation-specific request parameters and some common request parameters. For the complete list of common request parameters, see the Public request parameters section of the Accessing Server APIs topic.

ParameterTypeRequiredDescription
FromUserIdStringYesThe UserID of the user.
  • For querying one-to-one conversation messages, fill in the UserID of any participant in the conversation.
  • For querying group conversation messages, you can fill in the UserID of any registered user.
ConvIdStringYesThe conversation ID.
  • For one-to-one conversation messages, fill in the UserID of the other participant.
  • For group conversation messages, fill in the groupID of the target group.
ConvTypeStringYesThe conversation type:
  • 0: one-to-one conversation.
  • 2: Group conversation.
MsgSeqListArray of NumberYesA list of message sequences to query. The list has an upper limit of 20.
Note
For adjustments, please contact ZEGOCLOUD technical support.
MsgSeq retrieval method:
  • If you need to query one-to-one conversation messages sent by the client, retrieve MsgSeq via the Callback on message sent.
  • If you need to query one-to-one messages sent by the server API Send a one-to-one message, get MsgSeq from the API response data.
  • If you need to query group conversation messages sent by the server API Send group messages, get MsgSeq from the API response data.

Sample Request

  • Request URL:

    Untitled
    https://zim-api.zego.im/?Action=QueryMessagesByMsgSeq
    &<Common request parameters>
    
    1
    Copied!
  • Request Body:

    Untitled
    {
        "FromUserId": "user0",
        "ConvId": "user1",
        "ConvType": 0,
        "MsgSeqList": [
            1,
            2,
            3
        ]
    }
    
    1
    Copied!

Response Parameters

ParameterTypeDescription
CodeNumberReturn code.
MessageStringDescription of the result.
RequestIdStringRequest ID.
MessageListArray of ObjectList of returned messages, details in MessageList Structure.

MessageList Structure

ParameterTypeDescription
SenderStringMessage sender.
MsgTypeNumberMessage type:
  • 1: Text.
  • 10: Multi-item.
  • 11: Image.
  • 12: File.
  • 13: Audio.
  • 14: Video.
  • 31: Revoked.
  • 32: Tip.
  • 200: Custom.
SubMsgTypeNumberSpecific custom type. The value is filled by the user when sending a custom message, and the valid range is [0, 200]. This parameter is meaningful only when MsgType is 200 (custom).
MsgBodyStringMessage content.
MsgIdNumberMessage ID, which can be used to determine the uniqueness of the message.
MsgSeqNumberMessage sequence.
PayloadStringMessage extension field.
MsgTimeNumberThe time when the server receives the message, in Unix timestamp format, in milliseconds (ms).
IsEmptyNumberWhether it is an empty message:
  • 0: Not an empty message.
  • 1: The message has been deleted (cannot be queried or deleted by the client via the API). Therefore, other response fields are empty.
  • 2: The message has been revoked.

MsgBody JSON String Parsing Result Parameters

Multimedia messages

Multi-Item messages

Revoked messages

Tip Messages

Sample Response

Untitled
{
    "Code": 0,
    "Message": "success",
    "RequestId": "343649807833778782",
    "MessageList": [
        {
            "Sender": "userA",
            "MsgType": 1,
            "MsgBody": "this is a message",
            "MsgId": 971503777289036700,
            "MsgSeq": 1,
            "Payload": "this is a payload",
            "MsgTime": 1705895412000,
            "IsEmpty": 0
        }
    ]
}
1
Copied!

Return Codes

Return CodeDescriptionSuggested Actions
660000001Server error.Please try again or contact ZEGOCLOUD Technical Support.
660000002Missing or invalid input parameters.Please check the input parameters.
660300005API call frequency exceeds AppID level limit.Please try again later or refer to the relevant documentation for frequency limits.
660700008Error retrieving user information.Please check if the UserID is correct.
660700015User not registered.Please register the user first.

Previous

Import group messages

Next

MessageBody introduction