Wednesday, May 25, 2011

Connecting to Salesforce from Google Apps Script via OAuth & RESTful API

Be sure that you get consumer key/secret pair by registering remote application in Salesforce, with callback URL to "https://spreadsheets.google.com/macros". Then set them as proper script properties of Google Spreadsheet.



Run "queryDataFromSalesforce" function from script editor.

6 comments:

Saqib Ali said...

Shinichi,

Thanks for putting this together. It seems like this script require a 2-Legged OAuth Token. How would I modify it to make use of 3-Legged OAuth in SF?

Thanks,
Saqib

t said...

Thanks for share..

I have a problem...It shows a error "Unexpected error" on that line
"var result = UrlFetchApp.fetch(sessionLoginUrl, options);"

What may be problem ?

Otto said...

The instructions should clarify which Salesforce Editions the code can interact with.
Most people may not be familiar with API calls; where the API calls are only valid for Salesforce Enterprise + Unlimited editions.

For clarification on editions, see http://www.sfdcstatic.com/assets/pdf/datasheets/DS_SalesCloud_EdCompare.pdf

--
Otto
http://www.ottograjeda.com

Otto said...

BTW:

The code does work for the developer edition of Salesforce aka Force.com;
users can register for a free developer account at this link to test the
OAuth code (it works!).

http://www.developerforce.com/events/regular/registration.php

--
Otto
http://www.ottograjeda.com

bluspider said...

Could not make it work with a multiple objects. I am trying to get fields from Account and Account owners (user object). Nothing wrong with the query. But I get 'unknown' for attributes from user object. Any idea?

bluspider said...

Could not make it work with a multiple objects. I am trying to get fields from Account and Account owners (user object). Nothing wrong with the query. But I get 'unknown' for attributes from user object. Any idea?