This is a set of simple samples written in Apps Script, which provide a minimal example of Google Shopping integration within a Google Workspace Apps Script environment.
This starter project provides a great place to start your experimentation into the Google Merchant API for Shopping.
Create a new Apps Script project at script.google.com or re-use an existing one. Ensure your project is using the V8 runtime (enabled by default in new projects).
By default, Apps Script automatically creates and manages a default Google Cloud Platform (GCP) project for your script. While this is sufficient for quick testing, we recommend creating and linking a standard GCP project for more complex or advanced setups.
You must enable the Merchant API in your Apps Script project to use the Advanced Services. You can do this in one of two ways:
This method allows you to enable all required services at once by copying the configuration:
- Open your Apps Script project.
- At the left, click Project Settings (gear icon).
- Check the box for Show "appsscript.json" manifest file in editor.
- At the left, click Editor (
< >). You should now seeappsscript.jsonin the file list. - Open
appsscript.jsonand replace its content with the contents of theappsscript_v1.jsonfile located in theapps_script/directory.
- Open your Apps Script project.
- At the left, click Editor (
< >). - Next to Services, click Add a service (
+). - Select a Google Merchant API service (e.g.,
merchantapi), rename it to correspond with the code samples (for exampleMerchantApiInventories) and click Add. - Repeat for other required services (Accounts, Products, Reports, DataSources).
For more detailed instructions, see the official Google Merchant API Service guide.
Apps Script uses OAuth 2.0 with the credentials of the logged-in user and the GCP project associated with your script. Service Account authentication is not supported.
When you run the script, Apps Script will automatically prompt you to authorize the necessary scopes using your Google Account. You do not need to configure credentials files locally.
Before calling any v1 Merchant API method, you must register the GCP project
used to call the APIs. You only need to do this once.
- In your Apps Script project, create a new script file (e.g.,
Register.gs). - Copy the code from
examples/accounts/developerRegistration/v1/register_gcp_sample.gsin this repository and paste it into the new file. - Replace the placeholders
<ACCOUNT_ID>and<YOUR_EMAIL>in the code with your actual Merchant Center ID and email address. - In the editor's toolbar, select the
registerDeveloperfunction from the dropdown. - Click Run and authorize the script when prompted.
For more information, see Register as a developer.
- Select a sample file you want to run from this repository (e.g.,
examples/products/v1/list_products_sample.gs). - In your Apps Script project, create a new script file (e.g.,
Code.gs). - Copy the entire content of the sample file and paste it into your script file.
- Replace placeholders like
<MERCHANT_CENTER_ID>with your actual Merchant Center ID.
- In the editor's toolbar, select the main function of the sample you want to
run (e.g.,
productListforlist_products_sample.gs) from the function dropdown. - Click Run.
- View the execution logs at the bottom of the editor to see the results.