logo
In-app Chat
On this page

Query messages


Description

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

Request method and endpoint

  • 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 Common 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.
ConvTypeNumberYesThe 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:

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

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

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

Basic Parameters

ParameterTypeDescription
md5StringMD5 value of the file.
file_nameStringName of the file.
file_sizeStringFile size, in bytes (B).
download_urlStringDownload URL.
media_durationStringDuration of audio/video, in seconds (s).

Extended Parameters for Image Messages

For image messages, the following additional parameters are provided on top of the basic parameters.

ParameterTypeDescription
origin_image_widthIntWidth of the original image, in pixels (px).
origin_image_heightIntHeight of the original image, in pixels (px).
large_image_download_urlStringURL for downloading the large image.
large_image_widthIntWidth of the large image, in pixels (px).
large_image_heightIntHeight of the large image, in pixels (px).
thumbnail_download_urlStringURL for downloading the thumbnail image.
thumbnail_widthIntWidth of the thumbnail, in pixels (px).
thumbnail_heightIntHeight of the thumbnail, in pixels (px).

Extended Parameters for Video Messages

For video messages, the following additional parameters are provided on top of the basic parameters.

ParameterTypeDescription
video_first_frame_download_urlStringURL for downloading the first frame image of the video.
video_first_frame_widthIntWidth of the video first frame image, in pixels (px).
video_first_frame_heightIntHeight of the video first frame image, in pixels (px).

Multi-Item messages

ParameterTypeDescription
multi_msgArray of ObjectArray of items for the multi-item message.
└ msg_typeIntItem type:
  • 1: Text.
  • 11: Image.
  • 12: File.
  • 13: Audio.
  • 14: Video.
  • 200: Custom message.
└ sub_msg_typeIntThis parameter is returned only when msg_type is 200.
└ callback_contentObjectItem content.
  • When msg_type is 1 or 200, the message content can be read directly from this parameter.
  • For items with msg_type 11, 12, 13, or 14, refer to the section on Multimedia Message Structure for details on the fields in the message.

Revoked messages

ParameterTypeDescription
user_idStringThe UserID of the user who initiated the revoke.
revoke_timeNumberThe revocation timestamp, in milliseconds.
msg_typeNumberThe original message type.
payloadStringThe extension field carried during the revocation.
msg_statusNumberThe corresponding status of the revoked message:
  • 4: Revoked by the user.
  • 8: Revoked by the system.
  • 12: Revoked via server API.
  • 16: Revoked by group administrator.
  • 20: Revoked by group owner.
  • 24: Revoked due to failure to pass review.

Tip Messages

ParameterTypeDescription
typeNumberTips message type:
  • Group member change:
    • 1: Group created.
    • 2: Group dissolved.
    • 3: User joined group.
    • 4: Group member invited an external user.
    • 5: Group member left.
    • 6: User kicked out of the group.
  • Group member profile change:
    • 11: Group owner transferred.
    • 12: Group member role changed.
    • 13: Group member mute status changed.
  • Group profile change:
    • 30: Group name, avatar, or announcement changed.
    • 34: Group-wide mute status changed.
op_user_infoObjectThe user who triggered the Tips message (e.g., the user who created the group, the user who changed the group name).
└user_idStringUser ID.
└roleNumberUser's group role:
  • 1: Group owner.
  • 2: Group admin.
  • 3: Group member.
└group_member_nameStringUser's group member name.
└group_member_nicknameStringUser's group nickname.
target_usersArray of ObjectThe target users of the tip message operation (e.g., users invited to the group, users kicked out).
└user_idStringUser ID.
└roleNumberUser's group role:
  • 1: Group owner.
  • 2: Group admin.
  • 3: Group member.
└group_member_nameStringUser's group member name.
└group_member_nicknameStringUser's group nickname.
group_data_flagNumberWhen type is 30, this parameter indicates the modified group profile item.
  • 1: Group name.
  • 2: Group announcement.
  • 4: Group avatar.
group_noticeStringGroup announcement.
group_nameStringGroup name.
group_avatarStringGroup avatar.
forbidObject of GroupForbidWhen type is 34, this parameter indicates the group-wide mute object.
└is_all_forbidBoolWhether mute is applied to all members:
  • false: No.
  • true: Yes.
└forbid_role_listArray of NumberGroup member roles who are muted.
└forbid_expire_timeNumberThe timestamp of mute expiration, in milliseconds.
forbid_expire_timeNumberWhen type is 13, this parameter represents the timestamp of the group member's mute expiration, in milliseconds.
roleNumberWhen type is 12, this parameter represents the changed group member role.
  • 1: Group owner.
  • 2: Group admin.
  • 3: Group member.

Sample Response

{
    "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
        }
    ]
}

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 a group message

Next

Delete all messages from a one-to-one conversation user