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.

8 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?

Vimal Makwana said...

this code may be work but i don't know how to create oauth consumer key and secret key so display error like oauth error without any error code and line number...
so can anybody tell me how to generate it to communicate with salesforce...

thanks
vimal makwana

naga said...

I successfully connected to salesforce and fetching records , the same function i have configured as trigger.

If i ran manually ran it is asking me to authorize where i am entering salesforce credentails. after it is returning with the restuls.

But if the triggered trigger is not able to run successful might be it is losting the session.

if i again manually ran the trigger from google script it is excecuing success.

how should i overcome this problem