Get started with Merchant API

This page explains how you can create a Merchant Center account and upload a sample product using Merchant API.

Before you begin

Enable Merchant API in your Google Cloud project.

If the API integration is used in AppScript using the Shopping Content Service it creates a default Google Cloud project and enables the Merchant API service automatically. However, you still need to complete a one-time Developer registration before using Merchant API. For more information, see Using Merchant API Service in Apps Script.

Go to Google Cloud

Create an account

To use the Merchant API, you must have a Merchant Center account. To create a Merchant Center account, see Get started with Merchant Center.

Go to Merchant Center

Register as a developer

To use the Merchant API, you must link your Merchant Center account and your Google Cloud project using the Developer Registration method, as follows:

  1. Link Merchant Center and your Google Cloud project: The link is approved automatically, as the caller has a valid Access Token or API Key from the Google Cloud project , and is an authorized user of the Merchant Center account.

  2. Add an API Developer user to the Merchant Center account: The registration API adds an API Developer user to the Merchant Center account. If a user already exists they will be granted the new Access Type. In case of a new user, they will receive a Merchant Center email invite.

We recommend that you use the accounts.users.create method to add additional or backup API developers to verify that in case the person leaves your organization or gets deleted, you can still have valid developer registration.

After registration you can view the Registration status using GetDeveloperRegistration or unregister using UnregisterGCP.

The registration call is

POST https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/developerRegistration:registerGcp

{
  developer_email:"example-email@example.com"
}

After the request runs successfully, expect the response:

{
  "developerRegistration": {
    "name": "accounts/ACCOUNT_ID/developerRegistration",
    "gcpIds": ["GOOGLE_CLOUD_PROJECT_ID"]
  }
}

After the API developer is registered, you can use the accounts.users.patch method to grant them additional roles, such as STANDARD and ADMIN.

Get your account ID

You can obtain the account ID by using the accounts.list method.

You can use the Google APIs Explorer to run Merchant API requests. APIs Explorer uses Google OAuth 2.0 for authentication. Before running the requests, make sure that the Google OAuth 2.0 checkbox is ticked.

To authenticate using OAuth 2.0, you need to sign in to your Google Account, and then sign in to APIs Explorer. You also need to allow APIs Explorer to manage your product listings and accounts.

The following request shows how you can retrieve your account ID:

GET https://merchantapi.googleapis.com/accounts/v1beta/accounts

or

GET https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}

After the request successfully runs, you see the following response:

{
  "accounts": [
    {
      "name": "{ACCOUNT_NAME}",
      "accountId": "{ACCOUNT_ID}",
      "accountName": "{ACCOUNT_DISPLAY_NAME}",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    }
  ]
}

Copy the {ACCOUNT_ID} because you will need it to run other requests.

Create a primary products data source

To insert a product, you need a primary products data source. The following request shows how to create a data source you can use to insert a product to your account:

POST https://merchantapi.googleapis.com/datasources/v1beta/accounts/{ACCOUNT_ID}/dataSources HTTP/1.1

{
  "primaryProductDataSource": {
    "channel": "ONLINE_PRODUCTS",
    "contentLanguage": "en",
    "countries": [
      "US"
    ],
    "feedLabel": "US"
  },
  "name": "primary-data-source",
  "displayName": "Primary Products Data Source"
}

Replace the {ACCOUNT_ID} with the ID of the Merchant Center account you created.

After this request is successfully run, you see the following response:

{
  "name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
  "dataSourceId": "{DATASOURCE_ID}",
  "displayName": "Primary Products Data Source",
  "primaryProductDataSource": {
    "channel": "ONLINE_PRODUCTS",
    "feedLabel": "US",
    "contentLanguage": "en",
    "countries": [
      "US"
    ],
    "defaultRule": {
      "takeFromDataSources": [
        {
          "self": true
        }
      ]
    }
  },
  "input": "API"
}

Copy the value of the name field because you will need it for inserting a product.

It takes a few minutes for the created data source to be available for inserting products.

You can view this data source in the Merchant Center UI. For more information, see How to find the Data sources tab.

Insert a product

To insert a sample product to your account, run the following request:

POST https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs:insert?dataSource={DATASOURCE_NAME} HTTP/1.1

{
  "channel": "ONLINE",
  "contentLanguage": "en",
  "feedLabel": "US",
  "name": "Red T-shirt",
  "attributes": {
    "gender": "Male",
    "brand": "New brand"
  },
  "offerId": "tshirt-123"
}

Replace {DATASOURCE_NAME} with the value you copied earlier.

After this request is successfully run, you see the following response:

{
  "name": "accounts/{ACCOUNT_ID}/productInputs/online~en~US~tshirt-123",
  "product": "accounts/{ACCOUNT_ID}/products/online~en~US~tshirt-123",
  "channel": "ONLINE",
  "offerId": "tshirt-123",
  "contentLanguage": "en",
  "feedLabel": "US",
  "attributes": {
    "brand": "New brand",
    "gender": "Male"
  }
}

The product ID for the newly created product is online~en~US~tshirt-123. You can use the accounts.products.get method to retrieve details about this product. You can also use the Merchant Center UI to view this product.