1

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?

  • remember to accept the answer if it proved useful, you have several posts with asnwers that have not been accepted. thanks – glls Oct 15 '18 at 19:34
1

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 help doc: https://developer.salesforce.com/docs/atlas.en-us.live_agent_rest.meta/live_agent_rest/live_agent_rest_Availability.htm

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...

enter image description here

| improve this answer | |
  • I didn't get which user info are you using to have authentication? Currently we have hosted live chat button on a website and i don't thing we can use guest users session id here. Can you elaborate more on authentication mechanism used here? – Chaithra K N May 23 '18 at 13:03
  • @ChaithraKN ...this is just an apex example...you dont need to pass access token simply make http request....I updated my answer! – Ayub May 23 '18 at 18:52
  • Is it possible to query the availability of the chat button in apex instead of rest API? – Chaithra K N Jun 3 '18 at 15:09
  • No you...can not for now. May be salesforce releases in it near future...but certainly you can use this code in apex as well for time being.. – Ayub Jun 4 '18 at 5:00
  • Yes, I agree we can use this in Apex, but i am concerned about no of API calls to salesforce. – Chaithra K N Jun 4 '18 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.