Is there a way to connect directly to Salesforce’s REST API directly from JS?

I get a cross origin error when I do an AJAX call, and am wondering if there´s a way to solve that.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The use of CORS (Cross-Origin Resource Sharing) is a good way to deal with the limitations around cross-origin requests.

CORS is a W3C recommendation that enables Web browsers to request
resources from origins other than their own (cross-origin requests).
For example, using CORS, a JavaScript script at could request a resource from

With Winter ’15 Salesforce added CORS support to the Chatter REST API. You can read more about it here: Winter ’15 Release Notes: CORS

James Ward has also created a proxy that adds the CORS headers to Salesforce’s REST APIs here: Salesforce CORS Proxy and he has written a blog post about it here: Cross-Origin Resource Sharing (CORS) for

Method 2

You cannot use REST API directly. You need to have some proxy page which will set headers. Normally we use “ForceTK” library to route all request to proxy page.

Here are some articles by pat –

Example of using ForceTk using Nodejs

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x