function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Haroon AhmadHaroon Ahmad 

Integration with Google Apps Script

Hi,

 
I need to write some records from a Google spreadsheet to Salesforce.
 
The approach I'm taking is restful API and Google Apps Script.  So I plan to expose the methods on the Salesforce side.
 
The Google App script will call the restful  method on salesforce, which will take some parameters from the Google App Script.
 
My main doubt is around authentication from Google App Script to Salesforce.
 
I've read about oAuth as a way to authenticate. Is that the best way to do that? Are there some other easier options?
 
I'm trying to figure out the best way to connect to (oAuth vs Session ID).
 
Thanks a lot for your help!
 
-Haroon
Best Answer chosen by Admin (Salesforce Developers) 
Haroon AhmadHaroon Ahmad

I was able to make this example work. It is by Arun Nagarajan, a google engineer.

 

It uses salesforce rest api, oAuth, and google apps script.

 

https://github.com/entaq/GoogleAppsScript/tree/master/Salesforce.com

http://www.youtube.com/watch?v=9SEAmNDtlcA

 

If you have any questions please let me know.

All Answers

Haroon AhmadHaroon Ahmad

I've tried to get a SessionID using the following direction in the documentation.

 

But I keep getting the error: {"error":"invalid_grant","error_description":"authentication failure"}

 

Session ID Authorization
You can use a session ID instead of an OAuth 2.0 access token if you aren't handling someone else's password:
  1. Obtain a session ID, for example, a SOAP APIlogin() call returns the session ID. You may also have the session ID, for example as part of the Apex current context. If you need a session ID just for testing purposes during development, you can use the username-password OAuth flow in a cURL command similar to the following:
    curl https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=myclientid" -d "client_secret=myclientsecret" -d "mylogin@salesforce.com" -d "password=mypassword123456"
AshwaniAshwani

Hi,

 

The best way to authenticate with Google AppScript with salesforce is OAuth 2.0. It provides both online and offline access to salesforce.

To acheive this just authenticate by sending request as:

 

https://accounts.google.com/o/oauth2/auth?scope=[AppScript Scope]&redirect_uri=[Call back url defined]&response_type=code&display=popup&client_id=75xxxxxx961-7lsxxxxxxxx3utj87rcm3rke8etkulh.apps.googleusercontent.com

 

In return it will provide authorization code as parameter to the url which can be used to get access token and/or access token from refresh token. For more info read here: 

https://developers.google.com/accounts/docs/OAuth2WebServer

http://help.salesforce.com/help/doc/en/remoteaccess_oauth_refresh_token_flow.htm#request_access_token

 

For any doubt reply or mark it as solved if it solved your problem.

 

Thanks.

Haroon AhmadHaroon Ahmad

I was able to make this example work. It is by Arun Nagarajan, a google engineer.

 

It uses salesforce rest api, oAuth, and google apps script.

 

https://github.com/entaq/GoogleAppsScript/tree/master/Salesforce.com

http://www.youtube.com/watch?v=9SEAmNDtlcA

 

If you have any questions please let me know.

This was selected as the best answer