Get Started

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

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 merchant_user@example.com.

Make your first API request (without a line of code!)

Head over to the API Explorer
in our developer documentation for Products.list.

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
'merchantId' field 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 Products.insert,
Inventory.set, and
Accountstatuses.get.

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.

If you have not previously agreed to the terms of service needed to use Google APIs, then
you will be led through that process now.

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.

The new user will only have Standard access by default, which
means it will not be able to use methods that require other levels of access. For example,
most methods in the Accounts service require the user to have Admin access.
You can adjust the permissions for the new user in the Users settings panel.

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 suggest 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.

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.

From within the python directory, use pip to install needed package dependencies. More detailed
instructions are available in the accompanying README.md files.

$ pip install -r requirements.txt

Run the shopping/content/products/list.py file, 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 service-account.json.

Now that you have set up the samples configuration, run
shopping/content/products/list.py again.

$ 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.py as 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.

At this point, you've got a well suited environment for developing with
the Content API for Shopping. You can now move on to learning more about
Making Requests
and Best Practices.