Reputation: 137
I implemented some Python code to have my front-end interact with the SF LiveAgent REST API as documented here: https://developer.salesforce.com/docs/atlas.en-us.live_agent_rest.meta/live_agent_rest
Everything works fine except when I make a POST request to the /Chasitor/ChatEnd
endpoint. Here I get a 400 with the response in the title.
To me it seems this endpoint is not thoroughly documented. It's docs (https://developer.salesforce.com/docs/atlas.en-us.live_agent_rest.meta/live_agent_rest/live_agent_rest_ChatEnd.htm) says that the ChatEndReason
body is required, but under the "Request Bodies for Live Agent REST API" there is no such body documented. Simply passing a dictionary with reason
as is suggested in ChatEnd
endpoint docs does not work.
Here is my code for this request:
import requests
response = requests.post(
endpoint + '/Chasitor/ChatEnd',
headers={
'X-LIVEAGENT-SESSION-KEY': session_info['key'],
'X-LIVEAGENT-AFFINITY': session_info['affinityToken'],
'X-LIVEAGENT-API-VERSION': '46'
},
data=json.dumps({'reason':'client'})
)
endpoint
is simply the url of my SF instance. session_info
a dict that contains the necessary infos.
The same request to the /Chasitor/ChatMessage
endpoint works fine (see below), as do all other requests I make. I suspect the body needs to look different, but I have no idea how.
response = requests.post(
endpoint + '/Chasitor/ChatMessage',
headers={
'X-LIVEAGENT-SESSION-KEY': session_info['key'],
'X-LIVEAGENT-AFFINITY': session_info['affinityToken'],
'X-LIVEAGENT-API-VERSION': '46'
},
data=json.dumps({'text': message})
)
Upvotes: 0
Views: 839
Reputation: 137
In the end I found through trial and error that the issue was caused by the payload. There is a hint in the docs, but in my opinion it is not well documented:
Request body:
ChatEndReason—Include the ChatEndReason parameter in the request body of your request to specify the reason that the chat ended. This parameter is required. For example: {reason: “client”}.
The type ChatEndReason
needs to be included in the payload. Therefore {'type':'ChatEndReason', 'reason':'client'}
worked.
Upvotes: 1