Content API for Shopping v2.1 - Google Apps Script

34 views
Skip to first unread message

Jason Gonzales

unread,
Sep 24, 2019, 5:37:46 PM9/24/19
to Google Apps Script Community

Hello,

Currently Google Apps Scripts Advanced Google Services only supports v2 of the Content API for Shopping. 

Are there any plans to add support for v2.1 of the API?


Link to Content API migration document: https://developers.google.com/shopping-content/v2/migration

Thank you

contentapiv2.png

Dimu Designs

unread,
Sep 24, 2019, 6:30:58 PM9/24/19
to Google Apps Script Community
You can use the latest version of that API by setting the required scopes (see reference documentation) in your manifest file (appsscript.json) and using UrlFetchApp.fetch() to call the REST API endpoints directly.

Jason Gonzales

unread,
Sep 24, 2019, 6:54:19 PM9/24/19
to Google Apps Script Community
Wouldn't using this method require users to handle OAuth2 themselves and pass the accessToken through the fetch?

If there is a plan to support Content API for Shopping v2.1 I would rather wait and only change version in Advanced Google Services rather than making any larger changes to the codebase.

Primarily I am looking to see if Content API for Shopping v2.1 is on the roadmap for Google Apps Script since all client libraries have already been updated to the latest version.

Dimu Designs

unread,
Sep 24, 2019, 10:07:32 PM9/24/19
to google-apps-sc...@googlegroups.com
Wouldn't using this method require users to handle OAuth2 themselves and pass the accessToken through the fetch?

You will need to pass the accessToken directly to UrlFetchApp in an Authorization header. However, you can retrieve the access token pretty easily via ScriptApp.getOAuthToken (so you won't have to handle setting up the OAuth2 flow yourself). Once you add the proper scopes to your manifest, then the accessToken generated will have the permissions/authorization needed. Calls to UrlFetchApp.fetch will look something like this:

var response = UrlFetchApp.fetch(
   
"[REST-API endpoint]",
   
{
       
"method":"[POST|GET|PUT|PATCH|DELETE|OPTIONS]",
       
"contentType":"application/json", // optional
       
"headers":{
           
"Authorization":"Bearer " + ScriptApp.getOAuthToken()
       
},
       
"payload":JSON.stringify({...});
   
}
);

 
Reply all
Reply to author
Forward
0 new messages