Set up a client library

We recommend using the Google API client libraries to set up the Content API for Shopping. This guide uses the Python Content API client libraries as an example, but they're available for many popular programming languages and simplify common API tasks like authentication, sending requests, and parsing responses. For help setting up client libraries for other languages, see the README.md for the language within the googleads/googleads-shopping-samples repo on GitHub.

To set up the Google API client library for Python, complete the following steps:

  1. Create a directory for the client library's configuration and authentication files. Within your home directory, create the following directories:

    ~/shopping-samples/content/

  2. To download your service account credentials, complete the following steps:

    1. Go to the Google API library.
    2. Select a project in the menu at the top of the page. If you don't have one yet, create one by clicking New project.
    3. If you haven't already enabled the Content API for Shopping for this project, then search for it in the list of Google APIs and enable it.
    4. In the sidebar on the left, select Credentials. You may need to click the left-pointing arrow at the top left to see this.
    5. To set up a service account, select Create credentials, and then Service account.
    6. Name the new service account. This also serves as the default username for the service account ID. Record the service account ID, including the part after the '@' character, for later use. Click Create, then go through the optional steps of granting access to project and users, and click Done.
    7. You will be directed to the Service Accounts page where your new service account can be accessed.
  3. To obtain a JSON private key, click the service account, then the Keys tab. Click Add key > Create new key, and then select JSON as the key type. Click Create to download the private key to your computer. The new key downloads automatically.

  4. Rename the downloaded credentials file to service-account.json.

  5. Move the service-account.json file to your home directory/shopping-samples/content/.

  6. In your home directory/shopping-samples/content/, create an empty merchant-info.json file.

  7. In merchant-info.json, add the following text:

    {
    "merchantId": your Merchant Center merchant ID,
    "accountSampleUser": "the email address associated with your Merchant Center account"
    }
    
  8. Add the new service account as a user to your Merchant Center account. If you are a third-party developer, you will need to have your client do this step for you.

    1. Go to your Merchant Center account.
    2. In the settings of your Merchant Center account, select People and access.
    3. Click + Add person and use the service account ID as the email address for the new user.

    4. The use of the Accounts service requires Admin access, so select Admin.

    5. Click Add user to save preferences and be returned to the list of users. The service account ID is listed with the chosen user role.

    6. Repeat the process for all other service accounts you want to add.

  9. Clone (or download and unzip) the googleads/googleads-shopping-samples GitHub repo to any location on your computer; it does not have to be in your home directory or in ~/shopping-samples/content/.

  10. If you downloaded and unzipped the repo, instead of cloning it, rename the unzipped directory to googleads-shopping-samples.

  11. To install the required sample dependencies, in a terminal window, navigate to googleads-shopping-samples/python/ and run:

    pip install -r requirements.txt
    

You now have the Google API client library for Python configured and ready to use with the Content API. In the next section, you’ll create and send a request to insert a new product.