## API

*** ** * ** ***

### Authentication

To use the Merchant API for Shopping with a given Merchant Center account, you
must set up an [API Console](https://console.developers.google.com/) project. Google Cloud Console projects help
you manage API access and authentication for your Merchant API solution.

Depending on the use case, there are two ways to access the Merchant API:

- **OAuth 2.0** is recommended for getting access to a specific Merchant Center account through an application you developed for your users. The user will need to grant access to your account to submit data on their behalf.
- **A service account** is a special kind of account, typically used by an application rather than a person. A service account is identified by its email address, which is unique to the account.

Refer to how to authenticate [using OAuth 2.0 or a service
account](https://developers.google.com/merchant/api/guides/authorization/access-client-accounts).

> [!TIP]
> **Tip:** When submitting data as a Local Feed Partnership Provider, the service account email needs to be added to the list of MCA account users as calls will be authenticated through that account for all the MCA sub-accounts.

### Enable country settings

> [!IMPORTANT]
> **Important:** Before submitting offers' data you need to enable the specific local program.

Call [`liasettings.update`](https://developers.google.com/shopping-content/reference/rest/v2.1/liasettings/update) to specify the countries where you
plan to serve local.

More information on the Country Settings Target [page](https://developers.google.com/shopping-content/guides/how-tos/lia/configure-targets)

### Send offers data

There are two types of data: product and inventory data.

![offer_inventory_expiration](https://developers.google.com/static/merchant/storebuilder/images/blueprint/offer_inventory_expiration.png)

#### Send product and inventory data at once

Product and inventory data can be submitted at once using
[accounts.lfpInventories.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpInventories/insert)

The field "GTIN" in fact will work as a product identifier for Google's catalog
and a product feed will be automatically created.

This automatically created feed will show in the target Merchant Center as
"Local Feed Provider" feed with the relevant offers associated with.

This method works well if all the merchant's products have a GTIN and no further
features are going to be enabled (like Merchant Hosted Local Store Front basic).
If you plan to enable MHLSF for your merchants, sending a dedicated product feed
is the recommended setup.

The same procedure can work using [accounts.lfpSales.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpSales/insert)

In this case the data refers to a Sale event for a particular product at a
particular time.

##### Send product and inventory data separately

If GTINs are not widely available or you would rather take advantage of an
existing product feed in the Target Merchant Center account or you want to
enable MHLSF for your merchants, you need to have a specific Local Product Feed.

This can be enabled by calling [accounts.productInputs.insert](https://developers.google.com/merchant/api/guides/products/overview)
first and inserting all the static values of a product. Remember to set the
`Channel` attribute to "local".

Learn more about basic product data [in this article](https://support.google.com/merchants/answer/7052112?sjid=13508477020884939094-NA#basic_product_data) and [API
general guidance for inserting products](https://developers.google.com/merchant/api/guides/products/overview).

The data flow is the following:

- Call [accounts.productInputs.insert](https://developers.google.com/merchant/api/guides/products/overview) first to start uploading products for your merchants
- Then Call [accounts.lfpInventories.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpInventories/insert) to submit inventory data.

Alternatively, inventory data can be sent through
[accounts.lfpSales.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpSales/insert). A machine learning model will then
predict price and quantity of the offers based on this data.

Example overview for [accounts.lfpInventories.insert, accounts.lfpSales.insert
accounts.lfpStores.insert](https://developers.google.com/merchant/api/guides/local-feeds-partnership/overview)

> [!IMPORTANT]
> **Important:** The offerId sent in [accounts.productInputs.insert](https://developers.google.com/merchant/api/guides/products/overview) needs to match the offerId in [accounts.lfpInventories.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpInventories/insert) so that offers are mapped correctly.

> [!IMPORTANT]
> **Important:** [accounts.lfpInventories.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpInventories/insert) has a **parent** parameter in the URL. This is your **LFP provider account** enabled by the Support team. Your retailer's merchant center account is in the request payload instead identified as **TargetMerchant**. This is the Merchant Center ID of the merchant to submit the inventory for.

> [!IMPORTANT]
> **Key Point:** Product data expires in 30 days and inventory data expires in 14 days. This is effective in removing unwanted products. Product and inventory data can be sent at once using [accounts.lfpInventories.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpInventories/insert) if GTINs are known for all offers. Alternatively you can use [accounts.productInputs.insert](https://developers.google.com/merchant/api/guides/products/overview) for product data and [accounts.lfpInventories.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpInventories/insert) (or [accounts.lfpSales.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpSales/insert)) for inventory data

### Send Business Profile data

When it is not possible to access the Merchant's Google Business Profile account
to retrieve the store codes, Store data can be sent through
[accounts.lfpStores.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpStores/insert) with your own specific store codes.

Note that when calling accounts.lfpinventories.insert or
accounts.lfpSales.insert the store Code will need to match the store Code
provided in lfp Stores requests.

> [!IMPORTANT]
> **Important:** If a matching store can't be found, the inventories or sales submitted with the store code won't be used. For higher matching rate success, the information provided should exactly match the details available in Google Maps for that particular store.

The response of [accounts.lfpStores.insert](https://developers.google.com/merchant/api/reference/rest/lfp_v1beta/accounts.lfpStores/insert) will also provide a
*matchingState* and *matchingStateHint* if the matching has failed.

> [!TIP]
> **Tip:** You should monitor those responses to log and address matching problems sooner rather than later and avoid building up unmatched stores, which won't be in a position to have offers served for.