Stay organized with collections
Save and categorize content based on your preferences.
The Shopping Content Service lets you use the
Google Content API for Shopping in
Apps Script. This API gives Google Merchant Center users the ability
to upload and manage their product listings and manage their Merchant
Center accounts.
For detailed information on this service, see the
reference documentation for the
Google Content API for Shopping. Like all advanced services in Apps Script, the
Shopping Content Service utilizes the same objects, methods, and parameters
as the public API.
Reference
For detailed information on this service, see the
reference documentation for the
Google Content API for Shopping API. Like all advanced services in Apps Script,
the advanced Sheets service uses the same objects, methods, and parameters as
the public API. For more information, see How method signatures are determined.
/** * Inserts a product into the products list. Logs the API response. */functionproductInsert(){constmerchantId=123456;// Replace this with your Merchant Center ID.// Create a product resource and insert itconstproductResource={'offerId':'book123','title':'A Tale of Two Cities','description':'A classic novel about the French Revolution','link':'http://my-book-shop.com/tale-of-two-cities.html','imageLink':'http://my-book-shop.com/tale-of-two-cities.jpg','contentLanguage':'en','targetCountry':'US','channel':'online','availability':'in stock','condition':'new','googleProductCategory':'Media > Books','productType':'Media > Books','gtin':'9780007350896','price':{'value':'2.50','currency':'USD'},'shipping':[{'country':'US','service':'Standard shipping','price':{'value':'0.99','currency':'USD'}}],'shippingWeight':{'value':'2','unit':'pounds'}};try{response=ShoppingContent.Products.insert(productResource,merchantId);// RESTful insert returns the JSON object as a response.console.log(response);}catch(e){// TODO (Developer) - Handle exceptionsconsole.log('Failed with error: $s',e.error);}}
List products
This example demonstrates how to list your products for a given merchant
center account.
/** * Lists the products for a given merchant. */functionproductList(){constmerchantId=123456;// Replace this with your Merchant Center ID.letpageToken;letpageNum=1;constmaxResults=10;try{do{constproducts=ShoppingContent.Products.list(merchantId,{pageToken:pageToken,maxResults:maxResults});console.log('Page '+pageNum);if(products.resources){for(leti=0;i < products.resources.length;i++){console.log('Item ['+i+'] ==> '+products.resources[i]);}}else{console.log('No more products in account '+merchantId);}pageToken=products.nextPageToken;pageNum++;}while(pageToken);}catch(e){// TODO (Developer) - Handle exceptionsconsole.log('Failed with error: $s',e.error);}}
Batch insert products
This example uses
Products.custombatch
to insert three products at the same time.
/** * Batch updates products. Logs the response. * @param {object} productResource1 The first product resource. * @param {object} productResource2 The second product resource. * @param {object} productResource3 The third product resource. */functioncustombatch(productResource1,productResource2,productResource3){constmerchantId=123456;// Replace this with your Merchant Center ID.custombatchResource={'entries':[{'batchId':1,'merchantId':merchantId,'method':'insert','productId':'book124','product':productResource1},{'batchId':2,'merchantId':merchantId,'method':'insert','productId':'book125','product':productResource2},{'batchId':3,'merchantId':merchantId,'method':'insert','productId':'book126','product':productResource3}]};try{constresponse=ShoppingContent.Products.custombatch(custombatchResource);console.log(response);}catch(e){// TODO (Developer) - Handle exceptionsconsole.log('Failed with error: $s',e.error);}}
Update account-level taxes
This sample code uses
Accounttax to update the
account-level tax information for a Merchant Center account. See our
API guide for more
information about account-level tax and shipping.
/** * Updates content account tax information. * Logs the API response. */functionupdateAccountTax(){// Replace this with your Merchant Center ID.constmerchantId=123456;// Replace this with the account that you are updating taxes for.constaccountId=123456;try{constaccounttax=ShoppingContent.Accounttax.get(merchantId,accountId);console.log(accounttax);consttaxInfo={accountId:accountId,rules:[{'useGlobalRate':true,'locationId':21135,'shippingTaxed':true,'country':'US'},{'ratePercent':3,'locationId':21136,'country':'US'},{'ratePercent':2,'locationId':21160,'shippingTaxed':true,'country':'US'}]};console.log(ShoppingContent.Accounttax.update(taxInfo,merchantId,accountId));}catch(e){// TODO (Developer) - Handle exceptionsconsole.log('Failed with error: $s',e.error);}}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-18 UTC."],[[["\u003cp\u003eThe Shopping Content Service lets you manage Google Merchant Center product listings and accounts within Apps Script using the Google Content API for Shopping.\u003c/p\u003e\n"],["\u003cp\u003eThis is an advanced service that requires enabling before use and mirrors the functionality of the public API.\u003c/p\u003e\n"],["\u003cp\u003eProvided code samples demonstrate common tasks like inserting, listing, and batch-updating products, as well as updating account-level tax information.\u003c/p\u003e\n"],["\u003cp\u003eFor comprehensive details, consult the Google Content API for Shopping reference documentation and support guide linked within the content.\u003c/p\u003e\n"]]],[],null,["The Shopping Content Service lets you use the\n[Google Content API for Shopping](/shopping-content) in\nApps Script. This API gives Google Merchant Center users the ability\nto upload and manage their product listings and manage their Merchant\nCenter accounts.\n\nFor detailed information on this service, see the\n[reference documentation](/shopping-content/v2/reference/v2) for the\nGoogle Content API for Shopping. Like all advanced services in Apps Script, the\nShopping Content Service utilizes the same objects, methods, and parameters\nas the public API.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n\nFor detailed information on this service, see the\n[reference documentation](/shopping-content/v2/reference/v2) for the\nGoogle Content API for Shopping API. Like all advanced services in Apps Script,\nthe advanced Sheets service uses the same objects, methods, and parameters as\nthe public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Google Content API for Shopping support guide](/shopping-content/support/contact-us).\n\nSample code\n\nWe now show how to use a few features of the Shopping Content Service.\n\nInsert product\n\nThis example demonstrates how to insert a single product into a given\nmerchant center account. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```gosu\n/**\n * Inserts a product into the products list. Logs the API response.\n */\nfunction productInsert() {\n const merchantId = 123456; // Replace this with your Merchant Center ID.\n // Create a product resource and insert it\n const productResource = {\n 'offerId': 'book123',\n 'title': 'A Tale of Two Cities',\n 'description': 'A classic novel about the French Revolution',\n 'link': 'http://my-book-shop.com/tale-of-two-cities.html',\n 'imageLink': 'http://my-book-shop.com/tale-of-two-cities.jpg',\n 'contentLanguage': 'en',\n 'targetCountry': 'US',\n 'channel': 'online',\n 'availability': 'in stock',\n 'condition': 'new',\n 'googleProductCategory': 'Media \u003e Books',\n 'productType': 'Media \u003e Books',\n 'gtin': '9780007350896',\n 'price': {\n 'value': '2.50',\n 'currency': 'USD'\n },\n 'shipping': [{\n 'country': 'US',\n 'service': 'Standard shipping',\n 'price': {\n 'value': '0.99',\n 'currency': 'USD'\n }\n }],\n 'shippingWeight': {\n 'value': '2',\n 'unit': 'pounds'\n }\n };\n\n try {\n response = ShoppingContent.Products.insert(productResource, merchantId);\n // RESTful insert returns the JSON object as a response.\n console.log(response);\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```\n\nList products\n\nThis example demonstrates how to list your products for a given merchant\ncenter account. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```gosu\n/**\n * Lists the products for a given merchant.\n */\nfunction productList() {\n const merchantId = 123456; // Replace this with your Merchant Center ID.\n let pageToken;\n let pageNum = 1;\n const maxResults = 10;\n try {\n do {\n const products = ShoppingContent.Products.list(merchantId, {\n pageToken: pageToken,\n maxResults: maxResults\n });\n console.log('Page ' + pageNum);\n if (products.resources) {\n for (let i = 0; i \u003c products.resources.length; i++) {\n console.log('Item [' + i + '] ==\u003e ' + products.resources[i]);\n }\n } else {\n console.log('No more products in account ' + merchantId);\n }\n pageToken = products.nextPageToken;\n pageNum++;\n } while (pageToken);\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```\n\nBatch insert products\n\nThis example uses\n[Products.custombatch](/shopping-content/v2/reference/v2/products/custombatch)\nto insert three products at the same time. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```gosu\n/**\n * Batch updates products. Logs the response.\n * @param {object} productResource1 The first product resource.\n * @param {object} productResource2 The second product resource.\n * @param {object} productResource3 The third product resource.\n */\nfunction custombatch(productResource1, productResource2, productResource3) {\n const merchantId = 123456; // Replace this with your Merchant Center ID.\n custombatchResource = {\n 'entries': [\n {\n 'batchId': 1,\n 'merchantId': merchantId,\n 'method': 'insert',\n 'productId': 'book124',\n 'product': productResource1\n },\n {\n 'batchId': 2,\n 'merchantId': merchantId,\n 'method': 'insert',\n 'productId': 'book125',\n 'product': productResource2\n },\n {\n 'batchId': 3,\n 'merchantId': merchantId,\n 'method': 'insert',\n 'productId': 'book126',\n 'product': productResource3\n }\n ]\n };\n try {\n const response = ShoppingContent.Products.custombatch(custombatchResource);\n console.log(response);\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```\n\nUpdate account-level taxes\n\nThis sample code uses\n[Accounttax](/shopping-content/v2/reference/v2/accounttax) to update the\naccount-level tax information for a Merchant Center account. See our\n[API guide](/shopping-content/v2/how-tos/account-level-tax-shipping) for more\ninformation about account-level tax and shipping. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```gosu\n/**\n * Updates content account tax information.\n * Logs the API response.\n */\nfunction updateAccountTax() {\n // Replace this with your Merchant Center ID.\n const merchantId = 123456;\n\n // Replace this with the account that you are updating taxes for.\n const accountId = 123456;\n\n try {\n const accounttax = ShoppingContent.Accounttax.get(merchantId, accountId);\n console.log(accounttax);\n\n const taxInfo = {\n accountId: accountId,\n rules: [\n {\n 'useGlobalRate': true,\n 'locationId': 21135,\n 'shippingTaxed': true,\n 'country': 'US'\n },\n {\n 'ratePercent': 3,\n 'locationId': 21136,\n 'country': 'US'\n },\n {\n 'ratePercent': 2,\n 'locationId': 21160,\n 'shippingTaxed': true,\n 'country': 'US'\n }\n ]\n };\n\n console.log(ShoppingContent.Accounttax\n .update(taxInfo, merchantId, accountId));\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```"]]