Search code examples
restsalesforcepostmansalesforce-service-cloud

SalesForce Live Agent Rest API not working when using Postman


I'm currently testing out Live Agent in development. If I understand correctly I should be able to test out the rest API by executing Postman commands while passing the correct information.

I'm able to execute the System/SessionId request and get back the response with the key, id, and affinity token. However when I try to execute the Chasitor/ChasitorInit, I am getting "Status 200, OK" but in the https://eu11.salesforce.com/console , agent that is online, is not getting a request. This is what I am sending over the Postman - for Chasitor/ChasitorInit:

POST /chat/rest/Chasitor/ChasitorInit HTTP/1.1
Host: d.la1-c2-par.salesforceliveagent.com
X-LIVEAGENT-API-VERSION: 39
X-LIVEAGENT-AFFINITY: c01b1fa0
X-LIVEAGENT-SESSION-KEY: e29ca4be-0580-4769-85fd-0a2ae29efef1!1491574157856!+mmC0MgxsyXGOC5v3M4uKpCQHTg=
X-LIVEAGENT-SEQUENCE: 1
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 3e421cb9-e777-4a6c-9ead-8e14f1f8ff60

Payload:

{
"organizationId": "00D0Y0000xxxxx", 
"deploymentId": "5720Y0000xxxxx", 
"buttonId": "liveagent_button_online_5730Y0000xxxxxx", 
"sessionId": "e29ca4be-0580-4769-85fd-0a2ae29efef1", 
"userAgent": "", 
"language": "en-US", 
"screenResolution": "1900x1080", 
"visitorName": "Frank Underwood", 
"prechatDetails": [],  
"prechatEntities": [], 
"receiveQueueUpdates": true, 
"isPost": true 
}

What am I doing wrong? Why is there no chat request for the agent?

When I am using .html page to start a chat with Live agent - it works. Agent receives invite, can accept, and chat works. I tried to see what requests are sent when using .html javascript, but it appears it is using sockets - and that is beyond my debugging capabilities.

ALSO - if I then hijack the session key/affinity token from existing web chat with agent over to Postman - I am able to hijack session and continue sending/receiving messages from Postman. But I am not able to start a chat from Postman.


Solution

  • I figured it out. For this call:   /chat/rest/Chasitor/ChasitorInit

    I needed to provide buttonId - it should have been only    "buttonId": "5730Y000000L2ak".

    Apparently when using html JS, it gets this value out of "liveagent_button_online_5730Y000000L2ak".