Keep regional information up to date

You can use Merchant API to keep regional information for your online products up to date. This includes updating price and availability, and removing regions a product is no longer sold in.

If you're an ecommerce platform, you can use Merchant API to create an interface where your clients can update the regional pricing and availability of their products.

Update price and availability by region

Use regionalInventories.insert to update regional information for a product. This call replaces the full RegionalInventory resource, so make sure you include all fields. See Add regional information to online products for a code sample and more details.

View your existing regions

This section explains how to view the regions associated with a product or account.

By product

Use accounts.products.regionalInventories.list to list all the regional inventories connected to a specific product in your account. Use the region field to identify the region each regional inventory refers to.

Here's a sample you can use to list regional inventories for a product:

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.ListRegionalInventoriesRequest 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventory 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceClient.ListRegionalInventoriesPagedResponse 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to list all the regional inventories on a given product */ 
 public 
  
 class 
 ListRegionalInventoriesSample 
  
 { 
  
 private 
  
 static 
  
 String 
  
 getParent 
 ( 
 String 
  
 accountId 
 , 
  
 String 
  
 productId 
 ) 
  
 { 
  
 return 
  
 String 
 . 
 format 
 ( 
 "accounts/%s/products/%s" 
 , 
  
 accountId 
 , 
  
 productId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 listRegionalInventories 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 productId 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 RegionalInventoryServiceSettings 
  
 regionalInventoryServiceSettings 
  
 = 
  
 RegionalInventoryServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 String 
  
 parent 
  
 = 
  
 getParent 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 (), 
  
 productId 
 ); 
  
 try 
  
 ( 
 RegionalInventoryServiceClient 
  
 regionalInventoryServiceClient 
  
 = 
  
 RegionalInventoryServiceClient 
 . 
 create 
 ( 
 regionalInventoryServiceSettings 
 )) 
  
 { 
  
 //  The parent product has the format: accounts/{account}/products/{product} 
  
 ListRegionalInventoriesRequest 
  
 request 
  
 = 
  
 ListRegionalInventoriesRequest 
 . 
 newBuilder 
 (). 
 setParent 
 ( 
 parent 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending list regional inventory request:" 
 ); 
  
 ListRegionalInventoriesPagedResponse 
  
 response 
  
 = 
  
 regionalInventoryServiceClient 
 . 
 listRegionalInventories 
 ( 
 request 
 ); 
  
 int 
  
 count 
  
 = 
  
 0 
 ; 
  
 // Iterates over all rows in all pages and prints the regional inventory 
  
 // in each row. 
  
 for 
  
 ( 
 RegionalInventory 
  
 element 
  
 : 
  
 response 
 . 
 iterateAll 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 element 
 ); 
  
 count 
 ++ 
 ; 
  
 } 
  
 System 
 . 
 out 
 . 
 print 
 ( 
 "The following count of elements were returned: " 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 count 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 // An ID assigned to a product by Google. In the format 
  
 // channel:contentLanguage:feedLabel:offerId 
  
 String 
  
 productId 
  
 = 
  
 "online:en:label:1111111111" 
 ; 
  
 listRegionalInventories 
 ( 
 config 
 , 
  
 productId 
 ); 
  
 } 
 } 
  
 

cURL

  curl --location 
 'https://merchantapi.googleapis.com/inventories/v1/accounts/987654321/products/en~US~12345/regionalInventories' \ 
 --header 'Authorization: Bearer <API_TOKEN>' 
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\ApiCore\PagedListResponse; 
 use Google\Shopping\Merchant\Inventories\V1\RegionalInventory; 
 use Google\Shopping\Merchant\Inventories\V1\Client\RegionalInventoryServiceClient; 
 use Google\Shopping\Merchant\Inventories\V1\ListRegionalInventoriesRequest; 
 /** 
 * Class to list the `RegionalInventory` resources for the given product in your 
 * merchant account. The response might contain fewer items than specified by 
 * `pageSize`. If `pageToken` was returned in previous request, it can be 
 * used to obtain additional results. 
 * 
 * `RegionalInventory` resources are listed per product for a given account. 
 */ 
 class ListRegionalInventories 
 { 
 // ENSURE you fill in the merchant account and product ID for the sample to 
 // work. 
 private const PARENT = 'accounts/[INSERT_ACCOUNT_HERE]/products/[INSERT_PRODUCT_HERE]'; 
 /** 
 * Lists all the regional inventories of a given product. 
 * 
 * @param string $parent The `name` of the parent product to list `RegionalInventory` 
 *     resources for. 
 *     Format: `accounts/{account}/products/{product}` 
 */ 
 function listRegionalInventoriesSample(string $parent): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $regionalInventoryServiceClient = new RegionalInventoryServiceClient($options); 
 // Prepare the request message. 
 $request = (new ListRegionalInventoriesRequest()) 
 ->setParent($parent); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 // Page size is set to the default value. If you are returned more 
 // responses than your page size, this code will automatically 
 // re-call the service with the `pageToken` until all responses 
 // are returned. 
 $parameters = ['pageSize' => 25000]; 
 /** @var PagedListResponse $response */ 
 $response = 
 $regionalInventoryServiceClient->listRegionalInventories($request, $parameters); 
 /** @var RegionalInventory $element */ 
 foreach ($response as $element) { 
 printf('RegionalInventory data: %s%s', $element->serializeToJsonString(), PHP_EOL); 
 } 
 } catch (ApiException $ex) { 
 printf('Call failed with message: %s%s', $ex->getMessage(), PHP_EOL); 
 } 
 } 
 // Helper to execute the sample. 
 function callSample(): void 
 { 
 // Lists all the regional inventories of the parent product. 
 $this->listRegionalInventoriesSample($this::PARENT); 
 } 
 } 
 $sample = new ListRegionalInventories(); 
 $sample->callSample();  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping 
  
 import 
 merchant_inventories_v1 
 # ENSURE you fill in the product ID for the sample to 
 # work. 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 _PRODUCT 
 = 
 "[INSERT_PRODUCT_HERE]" 
 _PARENT 
 = 
 f 
 "accounts/ 
 { 
 _ACCOUNT 
 } 
 /products/ 
 { 
 _PRODUCT 
 } 
 " 
 def 
  
 list_regional_inventories 
 (): 
  
 """Lists the `RegionalInventory` resources for the given product. 
 The response might contain fewer items than specified by 
 `pageSize`. If `pageToken` was returned in previous request, it can be 
 used to obtain additional results. 
 `RegionalInventory` resources are listed per product for a given account. 
 """ 
 # Gets OAuth Credentials. 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Creates a client. 
 client 
 = 
 merchant_inventories_v1 
 . 
 RegionalInventoryServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Creates the request. 
 # Page size is set to the default value. 
 request 
 = 
 merchant_inventories_v1 
 . 
 ListRegionalInventoriesRequest 
 ( 
 parent 
 = 
 _PARENT 
 , 
 page_size 
 = 
 25000 
 ) 
 try 
 : 
 # Makes the request and catch and print any error messages. 
 # If you are returned more responses than your page size, this code 
 # will automatically re-call the service with the `pageToken` until all 
 # responses are returned. 
 page_result 
 = 
 client 
 . 
 list_regional_inventories 
 ( 
 request 
 = 
 request 
 ) 
 # Print the response. 
 for 
 response 
 in 
 page_result 
 : 
 print 
 ( 
 response 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 "List failed" 
 ) 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 list_regional_inventories 
 () 
  
 

You can use the regions.list method in Merchant API to view all the regions for your account.

Remove regions

Here's how to remove regions you no longer sell products in.

From products

If a product is no longer sold in a specific region, you should remove that regional inventory information from the product. You can use regionalInventories.delete to remove a specific regional inventory entry from a product.

Here's a sample you can use to remove a regional inventory entry from a product:

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.DeleteRegionalInventoryRequest 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventoryName 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.inventories.v1.RegionalInventoryServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to delete a regional inventory for a given product */ 
 public 
  
 class 
 DeleteRegionalInventorySample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 deleteRegionalInventory 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 productId 
 , 
  
 String 
  
 regionId 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 RegionalInventoryServiceSettings 
  
 regionalInventoryServiceSettings 
  
 = 
  
 RegionalInventoryServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 String 
  
 name 
  
 = 
  
 RegionalInventoryName 
 . 
 newBuilder 
 () 
  
 . 
 setAccount 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()) 
  
 . 
 setProduct 
 ( 
 productId 
 ) 
  
 . 
 setRegion 
 ( 
 regionId 
 ) 
  
 . 
 build 
 () 
  
 . 
 toString 
 (); 
  
 try 
  
 ( 
 RegionalInventoryServiceClient 
  
 regionalInventoryServiceClient 
  
 = 
  
 RegionalInventoryServiceClient 
 . 
 create 
 ( 
 regionalInventoryServiceSettings 
 )) 
  
 { 
  
 DeleteRegionalInventoryRequest 
  
 request 
  
 = 
  
 DeleteRegionalInventoryRequest 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 name 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending deleteRegionalInventory request" 
 ); 
  
 regionalInventoryServiceClient 
 . 
 deleteRegionalInventory 
 ( 
  
 request 
 ); 
  
 // no response returned on success 
  
 System 
 . 
 out 
 . 
 println 
 ( 
  
 "Delete successful, note that it may take up to 30 minutes for the delete to update in" 
  
 + 
  
 " the system." 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 // An ID assigned to a product by Google. In the format 
  
 // channel:contentLanguage:feedLabel:offerId 
  
 String 
  
 productId 
  
 = 
  
 "online:en:label:1111111111" 
 ; 
  
 // The ID uniquely identifying each region. 
  
 String 
  
 regionId 
  
 = 
  
 "1111111" 
 ; 
  
 deleteRegionalInventory 
 ( 
 config 
 , 
  
 productId 
 , 
  
 regionId 
 ); 
  
 } 
 } 
  
 

cURL

  curl --location --request DELETE 
 'https://merchantapi.googleapis.com/inventories/v1/accounts/987654321/products/en~US~12345/regionalInventories/123456' \ 
 --header 'Authorization: Bearer <API_TOKEN>' 
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Shopping\Merchant\Inventories\V1\Client\RegionalInventoryServiceClient; 
 use Google\Shopping\Merchant\Inventories\V1\DeleteRegionalInventoryRequest; 
 /** 
 * Deletes the specified `RegionalInventory` resource from the given product 
 * in your merchant account.  It might take up to an hour for the 
 * `RegionalInventory` to be deleted from the specific product. 
 * Once you have received a successful delete response, wait for that 
 * period before attempting a delete again. 
 */ 
 class DeleteRegionalInventory 
 { 
 // ENSURE you fill in the merchant account, product, and region ID for the 
 // sample to work. 
 private const ACCOUNT = 'INSERT_ACCOUNT_ID_HERE'; 
 private const PRODUCT = 'INSERT_PRODUCT_ID_HERE'; 
 private const REGION = 'INSERT_REGION_ID_HERE'; 
 /** 
 * Deletes a specific regional inventory of a given product. 
 * 
 * @param string $formattedName The name of the `RegionalInventory` resource 
 * to delete. 
 *     Format: `accounts/{account}/products/{product}/regionalInventories/{region}` 
 *     Please see {@see RegionalInventoryServiceClient::regionalInventoryName()} 
 *     for help formatting this field. 
 */ 
 function deleteRegionalInventorySample(string $formattedName): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $regionalInventoryServiceClient = new RegionalInventoryServiceClient($options); 
 // Prepare the request message. 
 $request = (new DeleteRegionalInventoryRequest()) 
 ->setName($formattedName); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $regionalInventoryServiceClient->deleteRegionalInventory($request); 
 print 'Delete call completed successfully.' . PHP_EOL; 
 } catch (ApiException $ex) { 
 printf('Call failed with message: %s%s', $ex->getMessage(), PHP_EOL); 
 } 
 } 
 /** 
 * Helper to execute the sample. 
 */ 
 function callSample(): void 
 { 
 // These variables are defined at the top of the file. 
 $formattedName = RegionalInventoryServiceClient::regionalInventoryName( 
 $this::ACCOUNT, 
 $this::PRODUCT, 
 $this::REGION 
 ); 
 // Deletes the specific regional inventory of the parent product. 
 $this->deleteRegionalInventorySample($formattedName); 
 } 
 } 
 $sample = new DeleteRegionalInventory(); 
 $sample->callSample();  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping 
  
 import 
 merchant_inventories_v1 
 # ENSURE you fill in the product ID and region ID 
 # for the sample to work. 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 _PRODUCT 
 = 
 "[INSERT_PRODUCT_HERE]" 
 _REGION 
 = 
 "[INSERT_REGION_HERE]" 
 _NAME 
 = 
 f 
 "accounts/ 
 { 
 _ACCOUNT 
 } 
 /products/ 
 { 
 _PRODUCT 
 } 
 /regionalInventories/ 
 { 
 _REGION 
 } 
 " 
 def 
  
 delete_regional_inventory 
 (): 
  
 """Deletes the specified `RegionalInventory` resource from the given product. 
 It might take up to an hour for the `RegionalInventory` to be deleted 
 from the specific product. Once you have received a successful delete 
 response, wait for that period before attempting a delete again. 
 """ 
 # Gets OAuth Credentials. 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Creates a client. 
 client 
 = 
 merchant_inventories_v1 
 . 
 RegionalInventoryServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Creates the request. 
 request 
 = 
 merchant_inventories_v1 
 . 
 DeleteRegionalInventoryRequest 
 ( 
 name 
 = 
 _NAME 
 , 
 ) 
 # Makes the request and catch and print any error messages. 
 try 
 : 
 client 
 . 
 delete_regional_inventory 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Delete successful" 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 "Delete failed" 
 ) 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 delete_regional_inventory 
 () 
  
 

It might take up to 30 minutes for a RegionalInventory entry to be removed from a product.

This call removes information for only the specified region , from only the specified product .

From accounts

To remove regions from your account where you no longer sell your products, use the accounts.products.regionalInventories.delete method.

Create a Mobile Website
View Site in Mobile | Classic
Share by: