Import a one-to-one message
Description
You can call this method to import a historical one-to-one message in chronological order from another instant messaging service to ZEGO Instant Messaging (ZIM).
A one-to-one chat is between two users (user A and user B). If user A deletes some messages, the message list of user A will differ from that of user B. Therefore, you need to call this method for user A and user B separately.
Request method and endpoint
- Request method: POST
- Request URL: https://zim-api.zego.im/?Action=ImportPeerMsg
- Transmission protocol: HTTPS
- QPS limit: 20 calls per second
Request parameters
The following table describes only the method-specific request parameters and some common request parameters. For the complete list of common request parameters, see Accessing Server APIs.
| Parameter | Type | Required | Description | 
|---|---|---|---|
| FromUserId | String | Yes | The ID of the message sender (registered). | 
| ToUserId | String | Yes | The ID of the message recipient (registered). | 
| MessageType | Number | Yes | Message type. For more information about message types applicable to a one-to-one chat, see MessageBody Introduction. Signaling messages are not supported. | 
| Priority | Number | Yes | Message priority (read Basic Concepts - Message Priority for details). Valid values: 
 | 
| MessageBody | Object | Yes | Message content. For more information about the format, see MessageBody Introduction-Applicable types of one-to-one chats. Offline push is not supported. Warning OfflinePushandHasReceiptare not supported. | 
| SubMsgType | Number | No (Yes if MessageTypeis200) | Custom message type. Value range: [0,200]. | 
| SearchedContent | String | No | The searched content of the custom message. This field is required only if MessageTypeis200and can contain up to 64 bytes in length. This field is required to search for associated custom messages on the client. | 
| SendMessageTime | Number | No | The Unix timestamp when the message was sent. Unit: ms. Import messages based on their sending timestamps in chronological order. 
 | 
| ImportedUserId | String | Yes | It must be either the FromUserIdor theToUserId, indicating the user whose message list is to be imported. | 
- The FromUserIdandToUserIdparameters can contain only digits, letters, and the following characters: '!', '#', '$', '%', '&', '(', ')', '+', '-', ':', ';', '<', '=', '.', '>', '?', '@', '[', ']', '^', '_', ' ', '{', '}', '|', '~'.
- We recommend that you use the SDK of the latest version for better experience.
- To receive a text message whose MessageTypeis1, the version of the receiving ZIM SDK needs to be 2.7.0 or later.
- To send and receive a custom message whose MessageTypeis200, the version of the sending and receiving ZIM SDKs needs to be 2.8.0 or later.
- If the version of the receiving ZIM SDK is 2.0.0 or later but earlier than 2.8.0, the ZIM SDK can receive a custom message but will identify the message type as unknown. In addition, it cannot obtain the message content. To obtain the message content, upgrade the ZIM SDK to 2.8.0 or later.
- If the version of the receiving ZIM SDK is 1.x.x, the ZIM SDK cannot receive a custom message and identify the message type as unknown.
Sample request
- 
Request URL: https://zim-api.zego.im/?Action=ImportPeerMsg &<Common request parameters>
- 
Request body: { "FromUserId": "u1", "ToUserId": "u2", "MessageType": 200, "Priority": 1, "MessageBody": { "Message": "hello world", "ExtendedData": "s" }, "SubMsgType": 110, "SearchedContent": "ex", "SendMessageTime": 123, "ImportedUserId": "u1" }
Response parameters
| Parameter | Type | Description | 
|---|---|---|
| Code | Number | The return code. | 
| Message | String | The description of the request result. | 
| RequestId | String | The request ID. | 
| MsgId | String | The message ID. | 
| MsgSeq | Number | The message sequence. | 
Sample response
{
    "Code": 0,
    "Message": "success",
    "RequestId": "343649807833778782",
    "MsgId": "6654861479614",
    "MsgSeq": 1
}Verify the result
After messages are imported successfully, call the ZIM server API Query the message list of one-on-one chats to check whether all one-to-one messages are imported.
Return codes
The following table describes only the return codes related to the business logic of the method. For the complete list of return codes, see Return codes.
| Return code | Description | Solution | 
|---|---|---|
| 660400001 | The message size exceeds the limit. | Check the message size. | 



