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.


 function checkAvailable(URL)
    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); }


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

   url : "https://host.salesforceliveagent.com/chat/rest/System/SessionId",
   requestHeaders: {
       "X-LIVEAGENT-AFFINITY": "null"
   method: "GET",
   onSuccess : function(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


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.