1

I'm trying to make a simple REST GET request to salesforce Live Agent API to check whether service is available.

I can make the simple GET request successfully from my Web based REST client (Chrome Plugin - Boomerang) but am unable to successfully make the request from JQuery $.ajax.

I am getting a 400 Bad Request error.

 $(document).ready(function(){
 checkAvailable("https://d.xxx-xx-xxx.salesforceliveagent.com/chat/rest/Visitor/Availability?org_id=xxxxxxxxxxxxxxx&deployment_id=xxxxxxxxxxxxxxx&Availability.ids=[xxxxxxxxxxxxxx]");
 });

 function checkAvailable(URL)
 {
$.ajax({
    url: URL,     
    type: "GET",
    beforeSend: function(xhr){
        xhr.setRequestHeader('X-LIVEAGENT-AFFINITY', "null");
        xhr.setRequestHeader('X-LIVEAGENT-API-VERSION', "41");
        },
    success: function(response) { alert('Success: ' + response); },
    error: function(req, err){ console.log('Error Message: ' + err); }
 });

 }
0

Hope it helps

to the extent of my research, Salesforce does not allow rest call from vf page js (I May be wrong)

But the problem that you are facing is same as mine the workaround that I found is using salesforce AJAX Toolkit

Try this code this may work

sforce.connection.remoteFunction({
   url : "https://host.salesforceliveagent.com/chat/rest/System/SessionId",
   requestHeaders: {
       "Content-Type":"application/json",
       "X-LIVEAGENT-API-VERSION": "41",
       "X-LIVEAGENT-AFFINITY": "null"
      },
   method: "GET",
   onSuccess : function(response) {
          alert(response);
      },
   onFailure : function(response) {
          alert("Failed" + response)
      }
});

Note: this tag is to be included

<script src="../../soap/ajax/41.0/connection.js" type="text/javascript">

Note: this has to be run first for ajax toolkit authentication

sforce.connection.sessionId='{!GETSESSIONID()}';

FYI: :-) (if you solve long polling problem ps mail me)

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.