Getting Chat History
In the chat history returned via this API, images, voices and videos are displayed as text-format [image], [voice] and [video]. For image messages that are more likely to contain important information, the image URL will be provided, and this capability will be available soon.
Calling Method
HTTP request method: POST https://api.weixin.qq.com/customservice/msgrecord/ getmsglist ?access_token=ACCESS_TOKEN POST data example is as follows:
{
"starttime" : 987654321,
"endtime" : 987654321,
"msgid" : 1,
"number" : 10000
}
Parameters
Parameter | Description |
---|---|
starttime | Start time, expressed as a Unix timestamp. |
endtime | End time, expressed as a Unix timestamp. Each query period should be limited to 24 hours. |
msgid | Message ID, sorted from small to large, starting from 1. |
number | Number of messages obtained each time, which is up to 10000. |
Response Description
{
"recordlist" : [
{
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk" ,
"opercode" : 2002,
"text" : " Hello. This is Customer Service test1. What can I help you?" ,
"time" : 1400563710,
"worker" : "test1@test"
},
{
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk" ,
"opercode" : 2003,
"text" : "Hello. What can I do for you?" ,
"time" : 1400563731,
"worker" : "test1@test"
}
],
"number":2,
"msgid":20165267
}
Parameters
Parameter | Description |
---|---|
worker | Complete Customer Service account, in the format of "Account prefix@Official Account's Weixin ID" |
openid | User ID |
opercode | Operation code: 2002 (Customer Service sends message); 2003 (Customer Service receives message) |
text | Chat history |
time | Operation time, expressed as a Unix timestamp. |
Error code
Error Code | Description |
---|---|
65400 | API unavailable, because Customer Service is not enabled or updated to the latest version. |
65416 | Invalid query parameter |
65417 | Query period exceeds the limit |
Calling Example
First request: https://api.weixin.qq.com/customservice/msgrecord/ getmsglist ?access_token=ACCESS_TOKEN POST data example is as follows:
{
"starttime" : 1464710400,
"endtime" : 1464796800,
"msgid" : 1,
"number" : 10000 }
Response: {
"recordlist"
: [
{
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk" ,
"opercode" : 2002,
"text" : " Hello. This is Customer Service test1. What can I help you?" ,
"time" : 1464710500 ,
"worker" : "test1@test"
},
{
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk" ,
"opercode" : 2003,
"text" : "Hello. What can I do for you?" ,
"time" : 1464710600 ,
"worker" : "test1@test"
},
......
],
"number": 10000 ,
"msgid": 20165258 } The requested number (10000) is the same as the returned number (10000), and there might be messages yet to be obtained. Enter msgid ( 20165258 ) into the next request.
Second request: https://api.weixin.qq.com/customservice/msgrecord/ getmsglist ?access_token=ACCESS_TOKEN POST data example is as follows:
{
"starttime" : 1464710400,
"endtime" : 1464796800,
"msgid" :
20165258 ,
"number" : 10000 } Response: {
"recordlist"
: [
{
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk" ,
"opercode" : 2002,
"text" : " Hello. This is Customer Service test1. What can I help you?" ,
"time" : 1464710700 ,
"worker" : "test1@test"
},
{
"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk" ,
"opercode" : 2003,
"text" : "Hello. What can I do for you?" ,
"time" : 1464710800 ,
"worker" : "test1@test"
},
......
],
"number":4,
"msgid":20165267 } The requested number (10000) is different from the returned number (10000), so the subsequent messages of the time period have been obtained.