Creating Chat Session

This API is used to create a chat session between the Customer Service and the user. If there is a chat session, 0 is returned. The designated Customer Service account must be online and linked to a Weixin ID.

Calling Method

HTTP request method: POST
https://api.weixin.qq.com/customservice/kfsession/create?access_token=ACCESS_TOKEN
POST data example is as follows:
   {
      "kf_account" : "test1@test",
      "openid" : "OPENID"
   } 

Parameters

Parameter Description
kf_account Complete Customer Service account, in the format of "Account prefix@Official Account's Weixin ID"
openid Follower's openid

Response Description

Example of response data (The returned JSON packet for a successful request):
   {
      "errcode" : 0,
      "errmsg"  :  "ok"
   }
 

Closing Chat Session

Calling Method

HTTP request method: POST
   https: //api.weixin.qq.com/customservice/kfsession/close?access_token=ACCESS_TOKEN
   POST data example is as follows:
   {
      "kf_account":"test1@test" ,
      "openid": "OPENID"
   }

Parameters

Parameter Description
kf_account Complete Customer Service account, in the format of "Account prefix@Official Account's Weixin ID"
openid Follower's openid

Response Description

Example of response data (The returned JSON packet for a successful request):
   {
      "errcode"
   : 0,
      "errmsg"
   :
  "ok"
   }

Common Error Code

Error Code Description
0 Successful
65400 API unavailable, because Customer Service is not enabled or updated to the latest version.
65401 Invalid Customer Service account
65402 The account cannot be used because it is not linked with a Weixin ID
65413 The chat information of the appropriate user does not exist
65414 The user is connected to another Customer Service
40003 Invalid openid

Getting User's Chat Status

This API is used to get a user's chat session. If it does not exist, the kf_account is empty.

Calling Method

HTTP request method: GET https://api.weixin.qq.com/customservice/kfsession/getsession?access_token=ACCESS_TOKEN&openid=OPENID 

Parameters

Parameter Description
openid Follower's openid

Response Description

Return data example (the JSON return result for a successful request):   {      "createtime": 123456789,      "kf_account": "test1@test"   }

Parameters

Parameter Description
kf_account The Customer Service that receives the chat. Null means no Customer Service receives the chat.
createtime The time when the chat is received

Common Error Code

Error Code Description
0 Successful
65400 API unavailable, because Customer Service is not enabled or updated to the latest version.
40003 Invalid openid

Getting Customer Service Chat List

Calling Method

HTTP request method: GET https://api.weixin.qq.com/customservice/kfsession/getsessionlist?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT |

Parameters

Parameter Description
kf_account Complete Customer Service account, in the format of "Account prefix@Official Account's Weixin ID"

Response Description

Example of response data (The returned JSON packet for a successful request):
   {
      "sessionlist"   : [
         {
            "createtime"   : 123456789,
            "openid"   :  "OPENID"
         },
         {
            "createtime"   : 123456789,
            "openid"   :  "OPENID"
         }
      ]
   } 

Getting List of Unconnected Chat Sessions

Calling Method

HTTP request method: GET https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token=ACCESS_TOKEN 

Response Description

Example of response data (The returned JSON packet for a successful request):
   {
      "count"   : 150,
      "waitcaselist"   : [
         {
            "latest_time"   : 123456789,
            "openid"   :  "OPENID"
         },
         {
            "latest_time"   : 123456789,
            "openid"   :  "OPENID"
         }
      ]
   } 

Parameters

Parameter Description
count Number of chat sessions not connected
waitcaselist List of unconnected chat sessions. Up to 100 data entries can be returned, sorted by visit time.
openid Follower's openid
latest_time The time when the follower sent the last message

Error Code

Error Code Description
0 Successful
65400 API unavailable, because Customer Service is not enabled or updated to the latest version.
65401 Invalid customer service account
65402 The Customer Service account cannot be used because it is not linked with a Weixin ID
65413 The chat information of the appropriate user does not exist
65414 The follower is connected to another Customer Service
65415 The designated Customer Service is offline
40003 Invalid openid