javascriptrestsalesforcesame-origin-policysalesforce-chatter

consume salesforce chatter rest service from pure javascript


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


Solution

  • 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