Documentation
zim In-app Chat
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • In-app Chat
  • Server APIs
  • Conversation related
  • Query the message list of one-on-one chats

Query the message list of one-on-one chats

Last updated:2024-03-28 15:11

Overview

You can call this operation to paginate and fetch the message list of a specific one-on-one chat for a specified user.

Operation prototype

  • Request method: POST
  • Request URL: https://zim-api.zego.im/?Action=QueryPeerMsg
  • Protocol: HTTPS
  • QPS limit: 20 calls 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.

Parameter Type Required Description
FromUserId
String
Yes
To query the list of the one-to-one chat messages between User A and User B, fill in the UserID of user A here.
ToUserId
String
Yes
Fill in the UserID of user B here.
Limit
Number
No
The number of messages to retrieve at a time, with a value range of (0, 100], defaulting to 10.

  • When the value ≤ 0, it is corrected to 10.
  • When the value > 100, it is corrected to 100.
Next
Number
No
Pagination flag for pulling messages. Fill in 0 for the first time, and then fill in the Next value returned from the previous call. When the returned Next is 0, it means that the message list has been completely retrieved.

For example, if there are 250 messages in the current one-on-one chat session and you call this interface to query:

  1. First call this interface, fill in 100 for Limit, and fill in 0 for Next to query the 1st to 100th messages; the Next value in the returned result is num1.
  2. Second call this interface, fill in 100 for Limit, and fill in num1 for Next to query the 101st to 200th messages; the Next value in the returned result is num2.
  3. Third call this interface, fill in 100 for Limit, and fill in num2 for Next to query the 201st to 250th messages; the query is complete, and the Next in the returned result is 0.

WithEmptyMsg
Number
No
Whether the returned result includes retracted messages and messages that have been deleted on the server.

  • 0: Default value, not included.
  • 1: Included.

The FromUserId and ToUserId parameter can contain only digits, letters, and the following characters: '!','#','$','%','&','(',')','+','-',':',';','<','=','.','>','?','@','[',']','^','_',' ','{','}','|','~'.

Sample request

  • Request URL:
https://zim-api.zego.im/?Action=QueryPeerMsg
&<Common request parameters>
  • Request message body:
{
"FromUserId": "u1",
"ToUserId": "u2",
"Limit": 10,
"Next": 0,
"WithEmptyMsg": 0
     }

Response parameters

Parameters Type Description
Code
Number
The return code.
Message
String
The description of the request result.
RequestId
String
The request ID.
Next
Number
Pagination flag.
  • Not 0: indicates that there is more conversation information to be returned, and this field needs to be set to the Next  parameter in the request to fetch more conversation information.
  • 0: indicates that the complete conversation list has been returned.
List
Number
Message list. Return the results in descending order by MsgTime.
Sender
String
Message sender ID.
MsgType
Number
Message type:
  • 1: Text.
  • 11: Image.
  • 12: Document.
  • 13: Audio.
  • 14: Video.
  • 200: Custom.
  • SubMsgType
    Number
    Specific custom type. The value is filled in by the user when sending a custom message, and the value range is [0, 200]. This parameter is only meaningful when MsgType is 200 (custom type).
    MsgBody
    String
    Message content.
    • When the message is sent by the client:
      • When msg_type is 1 (text type) or 200 (custom type), msg_body is the message content passed in when sending the message, and developers can directly read the message content.
      • When msg_type is 11, 12, 13, 14, which means the message is a media type, msg_body is a JSON string. Please use URLDecode to decode this JSON string and parse it according to the structure of the multimedia message to retrieve the data of various fields in the message. Please refer to the media message structure.
    • When the message is sent by the server, regardless of the message type, the content passed in when sending the message is directly returned.
    MsgId
    Number
    Message ID, which can be used to determine the uniqueness of the message.
    MsgSeq
    Number
    The message Seq.
    Payload
    String
    Message extension field.
    MsgTime
    Number
    Timestamp when the server receives the message, in Unix time format with milliseconds (ms) as the unit.
    IsEmpty
    Number
    Whether it is an empty message.

    • 0: Not empty.
    • 1: Message is deleted or has expired.
    • 2: Message is revoked.

    Explanation of parameters in the parsed result of the msg_body JSON string

    Parameter Type Description
    md5 String The MD5 value of the file.
    file_name String File name.
    file_size String File size in bytes (B).
    download_url String Download address.
    media_duration String The duration of the audio or video, in seconds (s).

    Sample response

    {
        "Code": 0
        "Message": "success",
        "RequestId": "343649807833778782",
        "Next": 1000,
        "List": [
            {
                "Sender": "user1",
                "MsgType": 1,
                "MsgBody": "This is a message.",
                "MsgId": 971503777289036700,
                "MsgSeq": 1,
                "Payload": "Payload",
                "MsgTime": 1705895412000,
                "IsEempy": 0
            }
        ]
    }

    Return codes

    The following table describes only the return codes related to the business logic of the operation. For the complete list of return codes, see Return codes.

    Return Code Description Solution
    660000002
    Invalid parameter.
    Check the input parameter.
    660300005
    The QPS limit specified in AppID is exceeded.
    Try again later.
    660500002
    FromUserId is not registered.
    Check if FromUserId is correct.
    Page Directory
    • Free trial
    • 提交工单
      咨询集成、功能及报价等问题
      电话咨询
      400 1006 604
      Get Consulting
      Scan Wechat QR code