How to Initiate and send Salesforce Chat Message using REST API?

How to Initiate and send Salesforce Chat Message using REST API?

Salesforce Chat REST API can be used to initiate a Chat, send message and also end the chat. “Chat API Endpoint” in Salesforce Setup should be used to make the REST API Requests.

1. Go to “Chat Settings” in Salesforce Setup.

2. Get the “Chat API Endpoint”.

3. Do a GET Request to get the Session Key, Session Id and Affinity Token.

Endpoint URL:

{{Chat API Endpoint}}System/SessionId

4. Do a POST Request to initiate the Chat. In the body, you have to pass Organization Id, Chat Deployment Id and Chat Button Id.

{{Chat API Endpoint}}Chasitor/ChasitorInit

Header:

Body:

Sample Body:

{
    "organizationId": {{LiveAgentOrgId}},
    "deploymentId": {{LiveAgentDeploymentId}},
    "sessionId": {{LiveAgentSessionId}},
    "buttonId": {{LiveAgentChatButtonId}},
    "screenResolution": "2560x1440",
    "userAgent": "Postman",
    "language": "en-US",
    "visitorName": "Test Contact",
    "prechatDetails": [], 
    "prechatEntities": [], 
    "receiveQueueUpdates": true,
    "isPost": true
}

5. Do a POST Request to send a Chat Message or Text.

Endpoint URL:

{{Chat API Endpoint}}Chasitor/ChatMessage

Header:

Body:

6. Do a POST Request to end the Chat.

Endpoint URL:

{{Chat API Endpoint}}Chasitor/ChatEnd

Header:

Body:

Output: 

Leave a Reply