Using Salesforce Chat REST API

Original Article:


  • Custom Experience:- Header, Footer, Navigation, Offline Form, Pre-chat Form
  • Security Reason:- Salesforce generated embedded service snippet code does not require authentication and works publicly. Also, the script may contain some dangerous Javascript functions like (eval(), create()) which may be against our company privacy policy.
  • Building any embedded web app which is tightly coupled with Salesforce Service Cloud.

Here are Salesforce REST API link:

Also, here are some useful content regarding same problem/requirement



  • We can orchestrate the request and response at this proxy server.
  • We can add the layers of security as well as this proxy server.


  • This server must have a very high throughput rate & low latency.
  • Must be able to cope with tons (yes, I mean it — huge numbers of HTTP request trips would be made) requests.
  • You can develop this in any technology, just for example, here are two ways-
  • Java: Here is a working repo that can be helpful:
  • Salesforce Apex REST Endpoint: Not an ideal approach keeping in mind the performance prerequisites of the server but still can work if there is not much traffic on the chat channel for you or you just want to play with it. This is explained further in this article.

Salesforce Apex REST Endpoint as Proxy Server

  • Develop an Apex class as below to make enabled for APEX REST


global with sharing class LiveChatService{


global static String doPost(String type, String payload) {

if(type == ‘availibity’){

responseBody = checkAgentAvailability();



public static String checkAgentAvailability(){

String endPoint = ‘'+BUTTONID+'&deployment_id='+DEPLOYMENTID+'&org_id='+ORGANIZATIONID;

HttpResponse response = makeHttpRequest(null, ‘GET’, endPoint);

return response.getBody();



  • Add this apex class to a site by using Guest User Profile.
  • After that, we can use this service as below in our client side code:

let CHATSERVICEENDPOINT = ‘https://<site URL>/services/apexrest/livechat/service’;

const resp = await fetch(CHATSERVICEENDPOINT, {

method: ‘POST’,

headers: {

‘Content-Type’: ‘application/json’


redirect: ‘follow’,

body: ‘{“type”:”availibity”, “payload”:””}’


const data = await resp.json();



A bad architect - Salesforce

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store