3

I read documentation:

https://resources.docs.salesforce.com/196/latest/en-us/sfdc/pdf/live_agent_rest.pdf https://piotrczechumski.wordpress.com/2014/06/22/live-agent-rest-api-documentation/

and tried to create a Live Agent Session by send this ajax request:

$.ajax({    
    type: "GET",
    url: "https://d.la1-c1-lon.salesforceliveagent.com/chat/rest/System/SessionId",
    headers: {
        "X-LIVEAGENT-API-VERSION" : 34,
        "X-LIVEAGENT-AFFINITY" : null
    },
    cache: false,
    response:'json',
    success: onSend
});

I suppose to receive parameters (clientPollTimeout, key, id), but server return Status Code:400 Bad Request.

  • That would indicate to me that the URL is not correct? – Eric Aug 7 '15 at 13:22
  • "d.la1-c1-lon.salesforceliveagent.com/chat/rest" is copy of Live Agent API endpoint. URl from documentation : "hostname/chat/rest/System/SessionId". As said in documentation, I replace "hostname" in this URL with API endpoint. – grimar Aug 7 '15 at 14:12
  • where you able to resolve this? I keep getting this error as well.@grimar – PepeFloyd Sep 9 '15 at 22:56
  • You will not be able to call this from JS as its creates a cross domain request and browser security will not allow you to make it work. Did you try with Datatype: "jsonp" ? – Prasanna Sep 26 '16 at 10:31
  • @grimar: Any resolution on this issue? – Kumara Ravuri Apr 6 '17 at 17:39
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()}';

Try Adding Host url to Remote site settings

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.