+ Start a Discussion
Marcel dos SantosMarcel dos Santos 

Live Agent REST API Ajax request

I'm trying to using the Salesforcde Live Agent REST API from a webpage using angular and ajax requests.
When I first try to obtain the SessionId, performing an ajax request to <server>/chat/rest/System/SessionId, the browser first submits an OPTIONS preflight request.

Salesforce returns a 400 error response because the request doesn't include the headers X-LIVEAGENT-API-VERSION nor X-LIVEAGENT-AFFINITY. To verify if that was really the problem, I tried to add those headers and submit the request again using Postman. That time I got an 405 method not allowed error. That means that Salesforce can't service an OPTIONS request for that endpoint.

For what it looks like, Salesforce Live Agent doesn't support CORS. Is that correct? I would like to access the API directly from the client, without having to submit a request to my server and then a request to Salesforce Live Agent Api. Is this possible? Is there some way to have the Live Agent REST API servicing Ajax requests?
Felipe PradoFelipe Prado
I'm having the same problem! Did you have any luck?
Marcel dos SantosMarcel dos Santos

Hi Felipe.

Unfortunately I didn't. I couldn't make api requests directly from the webpage. I tried also to hack the javascript libraries Salesforce provide to have a widget in my page communicating to the chat service without any luck. I spent weeks trying to figure this out and the only solution I found was to submit requests to my application server and from it I'll query the Salesforce API.
If you don't want or don't have the time to do that, the only solution would be using the Salesforce chat in a pop-up window or in an iframe inside your page.

Good luck

Sean XiaoSean Xiao
Hi, 
Have you ever fixed this issue? I am meeting the same problem and cannot figure out how to solve. If you've already found the solution, would you please post it?