Is it possible to have an api call to check whether chat button is online or offline ? We know that we can have chat button code which will show online or offline status. But instead of that, Is it possible to make it centralized by calling an api to salesforce to check whether agents are available or not?
Yes, you can do that. You must need to make an API call your live agent endpoint with providing button Id, org id and deployment id.
Here is the working sample:
String endpoint = 'https://d.la1-c1cs-phx.salesforceliveagent.com/chat/rest/Visitor/Availability?Availability.prefix=Visitor&Availability.ids=5733B00000000Wq&deployment_id=5723B00000000pn&org_id=00D9z000000Hhli'; HttpRequest createReq = new HttpRequest(); createReq.setEndpoint(endpoint); createReq.setHeader('X-LIVEAGENT-API-VERSION', '40'); createReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());//not required..just as best practice createReq.setHeader('Content-Type', 'application/json'); createReq.setMethod('GET'); createReq.setTimeout(30000); Http h = new Http(); HttpResponse createRes = h.send(createReq); system.debug(createRes.getBody());
Where Availability.ids = List of chat button ids; deployment_id = Live agent Deployment Id; org_id = Salesforce Internal org id.
Also, please note that given example is for Apex. Similarly you can make REST http call from any other type of language/platform to know the availability and you do not need to pass any access token/auth token...