The Content API for Shopping allows apps to interact directly with the Merchant Center platform, vastly increasing the efficiency of managing large or complex Merchant Center accounts. Some typical use cases include:
- Automated account management
- Product management on a per-product basis
- Datafeed scheduling
- Managing complex tax and shipping settings
With the Content API for Shopping you can build software that manages accounts from the customer level down to the product level. The API can do almost everything the Merchant Center website does, but programmatically. To help you get started, we offer code samples in Java, .NET, Python, PHP, Ruby, and Go.
This guide will help you create your first application using the Content API. Before you can start coding, there are a few things you need to do.
Set up your Merchant Center Account
Create a Merchant Center Account.
Configure your Tax & Shipping settings.
Be sure to remember which email you used to create this merchant center account, as you will need that later. In the screenshots, you'll see it represented as
Make your first API request (without a line of code!)
Head over to the API Explorer in our developer documentation for
Ensure that the logged in Google account is listed in the Users setting, available from the overflow menu.
In the API Explorer, make sure the Authentication setting says Google OAuth 2.0:
Click Accept to authorize a Google-created API Console Project to temporarily access your Merchant Center account on your behalf to make an API request. Note that this screen should come from google.com, and you should be signed in to your Merchant Center email address.
Enter your Merchant ID from your Merchant Center account into the
merchantIdfield of the form, and click Execute.
You should see a successful response. Congratulations! You've made your first Shopping API request.
If you have no products in your Merchant Center yet, there won't be any in the list. But never fear, we'll add some soon. At this point, you can hop to other requests and take a look at what they do. Since this is a RESTful API, all requests work similarly. Good next steps include
Retrieve a service account key for authentication
Merchant Center can automatically create a Google API Console project and associated service account key for you. Your application will authenticate with this key when using the Content API for Shopping.
Select Content API from the three-dot menu in Merchant Center.
Select the Authentication tab.
Click the + button to create a new API key.
Once the new API Console project has been created and a new service account created in that project, the service account ID will be added as a new user to your Merchant Center account. In addition, your browser will automatically download a JSON file that contains the service account key. If you lose this file, you cannot re-download it, but you can repeat the process above to create a new key.
If you already have an existing API Console project and want to use it instead, then here's what to do to set up Content API access for your existing project.
If you will be accessing your own Merchant Center account, we recommend using service accounts to simplify the authentication flow. Please check out the Service Accounts guide for details on how to set up a new service account. Once your account has been created, the service account key that you have downloaded and stored is used to authenticate, and you can receive the API token that you need to make calls to the API.
If you are interested in making calls on behalf of clients with their own Merchant Center accounts, then please see the Authorize Requests guide. However, for trying out the Content API, we suggest you set up a testing account and use that until you have finished development.
Your first authorized API request using Python
Now that you have a service account key, you can access your account using the available Samples code. This guide will use the Python samples to demonstrate using the API.
Download our Python samples from our GitHub page.
From within the
pythondirectory, use pip to install needed package dependencies. More detailed instructions are available in the accompanying
pip install -r requirements.txt
shopping/content/products/list.pyfile, similar to what we did in the API Sandbox earlier.
python -m shopping.content.products.list
If you haven't followed the configuration directions in the README accompanying the source files, you will get an error that no sample configuration could be found. Follow the directions in the README to create the configuration directory and to populate it with the appropriate information. The JSON file you downloaded while setting up your service account should be placed in that directory with the filename
Now that you have set up the samples configuration, run
python -m shopping.content.products.list
At this point, the Python script should finish executing, and print out either a list of products that it found, or a message that there were no products in your account. If you get an error such as "User cannot access account 1234567890", it's most likely because you have not set up the service account user as an authorized user in Merchant Center. From the API's standpoint, the API Console project sent a request on behalf of a user who was not on the list of authorized Merchant Center administrators, so it would, of course, reject that request.
You can experiment with running
shopping/content/products/list.pyas many times as you want, since it is a read-only request. You can also explore the many other samples that we've created for both Python and other languages.