consume salesforce chatter rest service from pure javascript

530 views Asked by At

I am creating a browser extension which posts to salesforce chatter using rest api.Once I get the access_token from OAuth user agent flow,I can not make call to rest services from javascript,due tobrowser same origin policy.I do not want to use a server as proxy,since I want to make the extension purely client side.

I tried JSONP workaround,but it only works for GET,I need POST to post a feed to salesforce chatter

is there a possible way.Please suggest some work around

4

There are 4 answers

0
user1517566 On BEST ANSWER

Maybe consider passing your call to a custom rest service in salesforce. Setup a global class with the @RestResource annotation, and then within that an doPost method to handle what you're passing, in your case to make the post.

You'll still need the Oauth step to retrieve token that is then passed in with the rest request via the Authorization : Bearer header message.

See a good post on this here https://wiki.developerforce.com/page/Creating_REST_APIs_using_Apex_REST

0
AtulRajguru9 On

One option is to use site like http://www.ajax-cross-domain.com/

Here is good reference on this matter http://www.d-mueller.de/blog/cross-domain-ajax-guide/

0
TheShadow On

Since Salesforce '15 you are able to configure CORS. Therefor whitelist your app domain and you can do whatever you want. Does not solve the problem to obtain an access_token. The only approach to obtain an access_token purely by javascript is to use the User-Agent Flow since the access Token is passed as URL Part....

0
Cloxure On

Use jsforce, you will need a proxy due to the CORS problem, sorry.