List your products data and product issues

After you've added products to your Merchant Center account, you can retrieve their final, processed state, including their current status and any data quality issues. This lets you to monitor your product inventory, diagnose problems, and verify your products are eligible to appear on Google.

This guide explains how to list your products and their associated issues using the Products and Reports sub-APIs.

Prerequisites

You must have products in your Merchant Center account. To learn how to add products, see the Add and manage products guide.

Special considerations

  • Processing delay:There is a delay, typically a few minutes, between when you a productInput is inserted or updated and when the changes are reflected in the final processed product as returned by the product's retrieval methods.
  • Products with no destinations:Products that do not have any intended destinations are automatically removed after approximately one week. A product does not have any intended destinations if the destinationStatuses list within its productStatus field is empty. You should regularly check this status to avoid unintended product deletions.

List all processed products

To get a list of all your final, processed products, use the products.list method. This method returns the Product resource, which represents the product as it appears in Merchant Center after all rules and data source merges have been applied.

The response is paginated. Use the pageSize parameter to specify the number of products to return on each page and the pageToken from the response to retrieve subsequent pages.

  GET https://merchantapi.googleapis.com/products/v1/accounts/ {ACCOUNT_ID} 
/products?pageSize=2 
 

A successful call returns a paginated list of Product resources.

  { 
  
 "products" 
 : 
  
 [ 
  
 { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/products/en~US~SKU12345" 
 , 
  
 "offerId" 
 : 
  
 "SKU12345" 
 , 
  
 "contentLanguage" 
 : 
  
 "en" 
 , 
  
 "feedLabel" 
 : 
  
 "US" 
 , 
  
 "dataSource" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/dataSources/12345" 
 , 
  
 "productAttributes" 
 : 
  
 { 
  
 "title" 
 : 
  
 "Classic Cotton T-Shirt" 
 , 
  
 "price" 
 : 
  
 { 
  
 "amountMicros" 
 : 
  
 "15990000" 
 , 
  
 "currencyCode" 
 : 
  
 "USD" 
  
 } 
  
 }, 
  
 "productStatus" 
 : 
  
 { 
  
 "destinationStatuses" 
 : 
  
 [ 
  
 { 
  
 "reportingContext" 
 : 
  
 "SHOPPING_ADS" 
 , 
  
 "approvedCountries" 
 : 
  
 [ 
  
 "US" 
  
 ] 
  
 } 
  
 ] 
  
 } 
  
 }, 
  
 { 
  
 "name" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/products/en~US~SKU67890" 
 , 
  
 "offerId" 
 : 
  
 "SKU67890" 
 , 
  
 "contentLanguage" 
 : 
  
 "en" 
 , 
  
 "feedLabel" 
 : 
  
 "US" 
 , 
  
 "dataSource" 
 : 
  
 "accounts/ {ACCOUNT_ID} 
/dataSources/ {DATASOURCE_ID} 
" 
 , 
  
 "productAttributes" 
 : 
  
 { 
  
 "title" 
 : 
  
 "Modern Linen Trousers" 
 , 
  
 "price" 
 : 
  
 { 
  
 "amountMicros" 
 : 
  
 "49990000" 
 , 
  
 "currencyCode" 
 : 
  
 "USD" 
  
 }, 
  
 "gtins" 
 : 
  
 [ 
  
 "123456789012" 
  
 ] 
  
 }, 
  
 "productStatus" 
 : 
  
 { 
  
 "destinationStatuses" 
 : 
  
 [ 
  
 { 
  
 "reportingContext" 
 : 
  
 "SHOPPING_ADS" 
 , 
  
 "disapprovedCountries" 
 : 
  
 [ 
  
 "US" 
  
 ] 
  
 } 
  
 ], 
  
 "itemLevelIssues" 
 : 
  
 [ 
  
 { 
  
 "code" 
 : 
  
 "invalid_gtin" 
 , 
  
 "severity" 
 : 
  
 "DISAPPROVED" 
 , 
  
 "resolution" 
 : 
  
 "merchant_action" 
 , 
  
 "attribute" 
 : 
  
 "gtins" 
 , 
  
 "reportingContext" 
 : 
  
 "SHOPPING_ADS" 
 , 
  
 "description" 
 : 
  
 "Invalid GTIN" 
 , 
  
 "detail" 
 : 
  
 "The value provided for the gtin attribute is not a valid GTIN." 
 , 
  
 "documentation" 
 : 
  
 "https://support.google.com/merchants/answer/6324461" 
 , 
  
 "applicableCountries" 
 : 
  
 [ 
  
 "US" 
  
 ] 
  
 } 
  
 ] 
  
 } 
  
 } 
  
 ], 
  
 "nextPageToken" 
 : 
  
 "CiAKGjZhY2NvdW50cy8xMjM0NS9wcm9kdWN0cy9vbmxpbmV" 
 } 
 

The following code samples show how to list all products.

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ListProductsRequest 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.Product 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductsServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductsServiceClient.ListProductsPagedResponse 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductsServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to list all the products for a given merchant center account */ 
 public 
  
 class 
 ListProductsSample 
  
 { 
  
 private 
  
 static 
  
 String 
  
 getParent 
 ( 
 String 
  
 accountId 
 ) 
  
 { 
  
 return 
  
 String 
 . 
 format 
 ( 
 "accounts/%s" 
 , 
  
 accountId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 listProducts 
 ( 
 Config 
  
 config 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Obtains OAuth token based on the user's configuration. 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 // Creates service settings using the credentials retrieved above. 
  
 ProductsServiceSettings 
  
 productsServiceSettings 
  
 = 
  
 ProductsServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates parent to identify the account from which to list all products. 
  
 String 
  
 parent 
  
 = 
  
 getParent 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 ProductsServiceClient 
  
 productsServiceClient 
  
 = 
  
 ProductsServiceClient 
 . 
 create 
 ( 
 productsServiceSettings 
 )) 
  
 { 
  
 // The parent has the format: accounts/{account} 
  
 // Page size is set to the maximum 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. 
  
 ListProductsRequest 
  
 request 
  
 = 
  
 ListProductsRequest 
 . 
 newBuilder 
 (). 
 setParent 
 ( 
 parent 
 ). 
 setPageSize 
 ( 
 1000 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending list products request:" 
 ); 
  
 ListProductsPagedResponse 
  
 response 
  
 = 
  
 productsServiceClient 
 . 
 listProducts 
 ( 
 request 
 ); 
  
 int 
  
 count 
  
 = 
  
 0 
 ; 
  
 // Iterates over all rows in all pages and prints the datasource in each row. 
  
 // Automatically uses the `nextPageToken` if returned to fetch all pages of data. 
  
 for 
  
 ( 
 Product 
  
 product 
  
 : 
  
 response 
 . 
 iterateAll 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 product 
 ); 
  
 // The product includes the `productStatus` field 
  
 // That shows approval and disapproval information. 
  
 count 
 ++ 
 ; 
  
 } 
  
 System 
 . 
 out 
 . 
 print 
 ( 
 "The following count of products were returned: " 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 count 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "An error has occured: " 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 listProducts 
 ( 
 config 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\ApiCore\PagedListResponse; 
 use Google\Shopping\Merchant\Products\V1\ListProductsRequest; 
 use Google\Shopping\Merchant\Products\V1\Product; 
 use Google\Shopping\Merchant\Products\V1\Client\ProductsServiceClient; 
 /** 
 * This class demonstrates how list all products in your Merchant Center account. 
 */ 
 class ListProducts 
 { 
 /** 
 * A helper function to create the parent string. 
 * 
 * @param array $accountId 
 *      The account that owns the product. 
 * 
 * @return string The parent has the format: `accounts/{account_id}` 
 */ 
 private static function getParent($accountId) 
 { 
 return sprintf("accounts/%s", $accountId); 
 } 
 /** 
 * Lists all products in your Merchant Center account. 
 * 
 * @param array $config 
 *      The configuration data used for authentication and getting the acccount 
 *      ID. 
 */ 
 public static function listProductsSample($config) 
 { 
 // Obtains OAuth token based on the user's configuration. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a client. 
 $productsServiceClient = new ProductsServiceClient($options); 
 // Creates parent to identify the account from which to list all products. 
 $parent = self::getParent($config['accountId']); 
 // Creates the request. 
 // Page size is set to the maximum 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. 
 $request = new ListProductsRequest(['parent' => $parent, 'page_size' => 1000]); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 echo "Sending list products request:\n"; 
 /** 
 * Call the listProducts service and get back a response object 
 * with all products. 
 * 
 * @var PagedListResponse $response 
 */ 
 $response = $productsServiceClient->listProducts($request); 
 /** 
 * Loop through every product and print out its data. 
 * 
 * @var Product $product 
 */ 
 foreach ($response as $product) { 
 // The product includes the `productStatus` field that shows approval 
 // and disapproval information. 
 printf( 
 'Product data: %s%s', 
 $product->serializeToJsonString(), PHP_EOL 
 ); 
 } 
 } catch (ApiException $e) { 
 printf('Call failed with message: %s%s', $e->getMessage(), PHP_EOL); 
 } 
 } 
 /** 
 * Helper to execute the sample. 
 * 
 * @return void 
 */ 
 public function callSample(): void 
 { 
 $config = Config::generateConfig(); 
 self::listProductsSample($config); 
 } 
 } 
 // Run the script 
 $sample = new ListProducts(); 
 $sample->callSample();  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping 
  
 import 
 merchant_products_v1 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 _PARENT 
 = 
 f 
 "accounts/ 
 { 
 _ACCOUNT 
 } 
 " 
 def 
  
 list_products 
 (): 
  
 """Lists the `Product` resources for a given account.""" 
 # Gets OAuth Credentials. 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Creates a client. 
 client 
 = 
 merchant_products_v1 
 . 
 ProductsServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Creates the request. Set the page size to the maximum value. 
 request 
 = 
 merchant_products_v1 
 . 
 ListProductsRequest 
 ( 
 parent 
 = 
 _PARENT 
 , 
 page_size 
 = 
 1000 
 ) 
 # Makes the request and catches and prints any error messages. 
 try 
 : 
 response 
 = 
 client 
 . 
 list_products 
 ( 
 request 
 = 
 request 
 ) 
 for 
 product 
 in 
 response 
 : 
 print 
 ( 
 product 
 ) 
 print 
 ( 
 "List request successful!" 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 "List request failed" 
 ) 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 list_products 
 () 
  
 

Apps_Script

  /** 
  
 * 
  
 Lists 
  
 all 
  
 products 
  
 for 
  
 a 
  
 given 
  
 Merchant 
  
 Center 
  
 account 
 . 
  
 */ 
 function 
  
 productList 
 () 
  
 { 
  
 // 
  
 IMPORTANT 
 : 
  
 // 
  
 Enable 
  
 the 
  
 Merchant 
  
 API 
  
 Products 
  
 sub 
 - 
 API 
  
 Advanced 
  
 Service 
  
 and 
  
 call 
  
 it 
  
 // 
  
 "MerchantApiProducts" 
  
 // 
  
 Replace 
  
 this 
  
 with 
  
 your 
  
 Merchant 
  
 Center 
  
 ID 
 . 
  
 const 
  
 accountId 
  
 = 
  
 '<MERCHANT_CENTER_ID>' 
 ; 
  
 // 
  
 Construct 
  
 the 
  
 parent 
  
 name 
  
 const 
  
 parent 
  
 = 
  
 'accounts/' 
  
 + 
  
 accountId 
 ; 
  
 try 
  
 { 
  
 console 
 . 
 log 
 ( 
 'Sending list Products request' 
 ); 
  
 let 
  
 pageToken 
 ; 
  
 // 
  
 Set 
  
 the 
  
 page 
  
 size 
  
 to 
  
 1000. 
  
 This 
  
 is 
  
 the 
  
 maximum 
  
 allowed 
  
 page 
  
 size 
 . 
  
 let 
  
 pageSize 
  
 = 
  
 1000 
 ; 
  
 console 
 . 
 log 
 ( 
 'Retrieved products below:' 
 ); 
  
 // 
  
 Call 
  
 the 
  
 Products 
 . 
 list 
  
 API 
  
 method 
 . 
  
 Use 
  
 the 
  
 pageToken 
  
 to 
  
 iterate 
  
 through 
  
 // 
  
 all 
  
 pages 
  
 of 
  
 results 
 . 
  
 do 
  
 { 
  
 response 
  
 = 
  
 MerchantApiProducts 
 . 
 Accounts 
 . 
 Products 
 . 
 list 
 ( 
 parent 
 , 
  
 { 
 pageToken 
 , 
  
 pageSize 
 }); 
  
 console 
 . 
 log 
 ( 
 response 
 ); 
  
 pageToken 
  
 = 
  
 response 
 . 
 nextPageToken 
 ; 
  
 } 
  
 while 
  
 ( 
 pageToken 
 ); 
  
 // 
  
 Exits 
  
 when 
  
 there 
  
 is 
  
 no 
  
 next 
  
 page 
  
 token 
 . 
  
 } 
  
 catch 
  
 ( 
 e 
 ) 
  
 { 
  
 console 
 . 
 log 
 ( 
 'ERROR!' 
 ); 
  
 console 
 . 
 log 
 ( 
 e 
 ); 
  
 } 
 } 
  
 

cURL

  curl -X GET \ 
 "https://merchantapi.googleapis.com/products/v1/accounts/ {ACCOUNT_ID} 
/products?pageSize=2" \ 
 -H "Authorization: Bearer <API_TOKEN>" 
 

Check product statuses and issues

The Merchant API provides several ways to view issues with your products and account.

Choose the right method for viewing issues

Here's a comparison of the different methods available for issue reporting:

Check the status of a product using the productStatus

To check the status of a product, examine the productStatus field within the Product resource returned by products.list or products.get . This field contains the aggregated status information for the product across all its destinations. It also contains issues related to inventories (local and regional) attached to given product.

The productStatus field includes:

  • destinationStatuses : An array indicating the approval status of the product for each destination (like SHOPPING_ADS ). It lists the countries where the product is approved, pending, or disapproved.
  • itemLevelIssues : An array containing any data validation or policy issues found for the product. Each issue includes a description, severity, the affected attribute, and documentation to help you resolve it.

Here is an example of a productStatus for a product that is disapproved for Shopping ads in the US due to an invalid GTIN:

  { 
  
 "productStatus" 
 : 
  
 { 
  
 "destinationStatuses" 
 : 
  
 [ 
  
 { 
  
 "reportingContext" 
 : 
  
 "SHOPPING_ADS" 
 , 
  
 "disapprovedCountries" 
 : 
  
 [ 
  
 "US" 
  
 ] 
  
 } 
  
 ], 
  
 "itemLevelIssues" 
 : 
  
 [ 
  
 { 
  
 "code" 
 : 
  
 "invalid_gtin" 
 , 
  
 "severity" 
 : 
  
 "DISAPPROVED" 
 , 
  
 "resolution" 
 : 
  
 "merchant_action" 
 , 
  
 "attribute" 
 : 
  
 "gtins" 
 , 
  
 "reportingContext" 
 : 
  
 "SHOPPING_ADS" 
 , 
  
 "description" 
 : 
  
 "Invalid GTIN" 
 , 
  
 "detail" 
 : 
  
 "The value provided for the gtin attribute is not a valid GTIN." 
 , 
  
 "documentation" 
 : 
  
 "https://support.google.com/merchants/answer/6324461" 
 , 
  
 "applicableCountries" 
 : 
  
 [ 
  
 "US" 
  
 ] 
  
 } 
  
 ] 
  
 } 
 } 
 

Filter products

You can filter products efficiently by using the reports.search method from the Reports sub-API instead of listing all products and filtering them on your side.

For example, to retrieve a list of only your disapproved products, you can build a reports.search query on the ProductView table to select products where the aggregated_reporting_context_status is NOT_ELIGIBLE_OR_DISAPPROVED . You can also filter by other attributes, for example availability or language_code . For more information on creating the filtering capabilities, see the Filter products guide section.

  POST https://merchantapi.googleapis.com/reports/v1/accounts/ {ACCOUNT_ID} 
/reports:search 
 
  { 
  
 "query" 
 : 
  
 "SELECT offer_id, id, title FROM product_view WHERE aggregated_reporting_context_status = 'NOT_ELIGIBLE_OR_DISAPPROVED'" 
 } 
 

The following code samples show how to filter for disapproved products.

Java

  import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.GetProductRequest 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.Product 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductsServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductsServiceSettings 
 ; 
 import 
  
 com.google.shopping.merchant.reports.v1.ReportRow 
 ; 
 import 
  
 com.google.shopping.merchant.reports.v1.ReportServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.reports.v1.ReportServiceClient.SearchPagedResponse 
 ; 
 import 
  
 com.google.shopping.merchant.reports.v1.ReportServiceSettings 
 ; 
 import 
  
 com.google.shopping.merchant.reports.v1.SearchRequest 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** 
 * This class demonstrates how to get the list of all the disapproved products for a given merchant 
 * center account. 
 */ 
 public 
  
 class 
 FilterDisapprovedProductsSample 
  
 { 
  
 // Gets the product details for a given product using the GetProduct method. 
  
 public 
  
 static 
  
 void 
  
 getProduct 
 ( 
 GoogleCredentials 
  
 credential 
 , 
  
 Config 
  
 config 
 , 
  
 String 
  
 productName 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Creates service settings using the credentials retrieved above. 
  
 ProductsServiceSettings 
  
 productsServiceSettings 
  
 = 
  
 ProductsServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 ProductsServiceClient 
  
 productsServiceClient 
  
 = 
  
 ProductsServiceClient 
 . 
 create 
 ( 
 productsServiceSettings 
 )) 
  
 { 
  
 // The name has the format: accounts/{account}/products/{productId} 
  
 GetProductRequest 
  
 request 
  
 = 
  
 GetProductRequest 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 productName 
 ). 
 build 
 (); 
  
 Product 
  
 response 
  
 = 
  
 productsServiceClient 
 . 
 getProduct 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 response 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 // Filters the disapproved products for a given Merchant Center account using the Reporting API. 
  
 // Then, it prints the product details for each disapproved product. 
  
 public 
  
 static 
  
 void 
  
 filterDisapprovedProducts 
 ( 
 Config 
  
 config 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 ReportServiceSettings 
  
 reportServiceSettings 
  
 = 
  
 ReportServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 try 
  
 ( 
 ReportServiceClient 
  
 reportServiceClient 
  
 = 
  
 ReportServiceClient 
 . 
 create 
 ( 
 reportServiceSettings 
 )) 
  
 { 
  
 // The parent has the format: accounts/{accountId} 
  
 String 
  
 parent 
  
 = 
  
 String 
 . 
 format 
 ( 
 "accounts/%s" 
 , 
  
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()); 
  
 // The query below is an example of a query for the productView that gets product informations 
  
 // for all disapproved products. 
  
 String 
  
 query 
  
 = 
  
 "SELECT offer_id," 
  
 + 
  
 "id," 
  
 + 
  
 "title," 
  
 + 
  
 "price" 
  
 + 
  
 " FROM product_view" 
  
 // aggregated_reporting_context_status can be one of the following values: 
  
 // NOT_ELIGIBLE_OR_DISAPPROVED, ELIGIBLE, PENDING, ELIGIBLE_LIMITED, 
  
 // AGGREGATED_REPORTING_CONTEXT_STATUS_UNSPECIFIED 
  
 + 
  
 " WHERE aggregated_reporting_context_status = 'NOT_ELIGIBLE_OR_DISAPPROVED'" 
 ; 
  
 // Create the search report request. 
  
 SearchRequest 
  
 request 
  
 = 
  
 SearchRequest 
 . 
 newBuilder 
 (). 
 setParent 
 ( 
 parent 
 ). 
 setQuery 
 ( 
 query 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending search report request for Product View." 
 ); 
  
 // Calls the Reports.search API method. 
  
 SearchPagedResponse 
  
 response 
  
 = 
  
 reportServiceClient 
 . 
 search 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Received search reports response: " 
 ); 
  
 // Iterates over all report rows in all pages and prints each report row in separate line. 
  
 // Automatically uses the `nextPageToken` if returned to fetch all pages of data. 
  
 for 
  
 ( 
 ReportRow 
  
 row 
  
 : 
  
 response 
 . 
 iterateAll 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Printing data from Product View:" 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 row 
 ); 
  
 // Optionally, you can get the full product details by calling the GetProduct method. 
  
 String 
  
 productName 
  
 = 
  
 "accounts/" 
  
 + 
  
 config 
 . 
 getAccountId 
 (). 
 toString 
 () 
  
 + 
  
 "/products/" 
  
 + 
  
 row 
 . 
 getProductView 
 (). 
 getId 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Getting full product details by calling GetProduct method:" 
 ); 
  
 getProduct 
 ( 
 credential 
 , 
  
 config 
 , 
  
 productName 
 ); 
  
 } 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Failed to search reports for Product View." 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 filterDisapprovedProducts 
 ( 
 config 
 ); 
  
 } 
 } 
  
 

PHP

  use Google\ApiCore\ApiException; 
 use Google\Shopping\Merchant\Products\V1\Client\ProductsServiceClient; 
 use Google\Shopping\Merchant\Products\V1\GetProductRequest; 
 use Google\Shopping\Merchant\Reports\V1\Client\ReportServiceClient; 
 use Google\Shopping\Merchant\Reports\V1\SearchRequest; 
 /** 
 * This class demonstrates how to get the list of all the disapproved products for a given merchant 
 * center account. 
 */ 
 class FilterDisapprovedProducts 
 { 
 /** 
 * Gets the product details for a given product using the GetProduct method. 
 * 
 * @param mixed $credentials The OAuth credentials. 
 * @param array $config The configuration data, including 'accountId'. 
 * @param string $productName The full resource name of the product to retrieve. 
 *      Format: accounts/{account}/products/{product} 
 */ 
 private static function getProduct( 
 $credentials, 
 array $config, 
 string $productName 
 ): void { 
 // Creates options config containing credentials for the client to use. 
 $options = ['credentials' => $credentials]; 
 // Creates a ProductsServiceClient. 
 $productsServiceClient = new ProductsServiceClient($options); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 // Construct the GetProductRequest. 
 // The name has the format: accounts/{account}/products/{productId} 
 $request = new GetProductRequest(['name' => $productName]); 
 // Make the API call. 
 $response = $productsServiceClient->getProduct($request); 
 // Prints the retrieved product. 
 // Protobuf messages are printed as JSON strings for readability. 
 print $response->serializeToJsonString() . "\n"; 
 } catch (ApiException $e) { 
 // Prints any errors that occur during the API call. 
 printf("ApiException was thrown: %s\n", $e->getMessage()); 
 } 
 } 
 /** 
 * Filters disapproved products for a given Merchant Center account using the Reporting API, 
 * then prints the details for each disapproved product. 
 * 
 * @param array $config The configuration data used for authentication and 
 *      getting the account ID. 
 */ 
 public static function filterDisapprovedProductsSample(array $config): void 
 { 
 // Gets the OAuth credentials to make the request. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates options config containing credentials for the Report client to use. 
 $reportClientOptions = ['credentials' => $credentials]; 
 // Creates a ReportServiceClient. 
 $reportServiceClient = new ReportServiceClient($reportClientOptions); 
 // The parent resource name for the report. 
 // Format: accounts/{accountId} 
 $parent = sprintf("accounts/%s", $config['accountId']); 
 // The query to select disapproved products from the product_view. 
 // This query retrieves offer_id, id, title, and price for products 
 // that are 'NOT_ELIGIBLE_OR_DISAPPROVED'. 
 $query = "SELECT offer_id, id, title, price FROM product_view" 
 . " WHERE aggregated_reporting_context_status = 'NOT_ELIGIBLE_OR_DISAPPROVED'"; 
 // Create the search report request. 
 $request = new SearchRequest([ 
 'parent' => $parent, 
 'query' => $query 
 ]); 
 print "Sending search report request for Product View.\n"; 
 // Calls the Reports.search API method. 
 try { 
 $response = $reportServiceClient->search($request); 
 print "Received search reports response: \n"; 
 // Iterates over all report rows in all pages. 
 // The client library automatically handles pagination. 
 foreach ($response->iterateAllElements() as $row) { 
 print "Printing data from Product View:\n"; 
 // Prints the ReportRow object as a JSON string. 
 print $row->serializeToJsonString() . "\n"; 
 // Get the full product resource name from the report row. 
 // The `id` field in ProductView is the product's full resource name. 
 // Format: `accounts/{account}/products/{product}` 
 $productName = $parent . "/products/" . $row->getProductView()->getId(); 
 // OPTIONAL: Call getProduct to retrieve and print full product details. 
 // Pass the original credentials and config. 
 print "Getting full product details by calling GetProduct method:\n"; 
 self::getProduct($credentials, $config, $productName); 
 } 
 } catch (ApiException $e) { 
 // Prints any errors that occur during the API call. 
 printf("ApiException was thrown: %s\n", $e->getMessage()); 
 } 
 } 
 /** 
 * Helper to execute the sample. 
 */ 
 public function callSample(): void 
 { 
 $config = Config::generateConfig(); 
 self::filterDisapprovedProductsSample($config); 
 } 
 } 
 // Run the script 
 $sample = new FilterDisapprovedProducts(); 
 $sample->callSample();  
 
 

Python

  from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.shopping.merchant_products_v1 
  
 import 
 GetProductRequest 
 from 
  
 google.shopping.merchant_products_v1 
  
 import 
 ProductsServiceClient 
 from 
  
 google.shopping.merchant_reports_v1 
  
 import 
 ReportServiceClient 
 from 
  
 google.shopping.merchant_reports_v1 
  
 import 
 SearchRequest 
 # Read the merchant account ID from the configuration file. 
 # This is a global variable used by the functions below. 
 _ACCOUNT_ID 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 get_product 
 ( 
 credentials 
 , 
 product_name 
 : 
 str 
 ): 
  
 """Gets the product details for a given product name. 
 Args: 
 credentials: The OAuth2 credentials. 
 product_name: The full resource name of the product, e.g., 
 "accounts/{account}/products/{product}". 
 """ 
 # Create a Products API client. 
 products_service_client 
 = 
 ProductsServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Prepare the GetProduct request. 
 # The name has the format: accounts/{account}/products/{productId} 
 request 
 = 
 GetProductRequest 
 ( 
 name 
 = 
 product_name 
 ) 
 # Call the API and print the response or any errors. 
 try 
 : 
 response 
 = 
 products_service_client 
 . 
 get_product 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 response 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 f 
 "Failed to get product 
 { 
 product_name 
 } 
 :" 
 ) 
 print 
 ( 
 e 
 ) 
 def 
  
 filter_disapproved_products 
 (): 
  
 """Filters disapproved products and prints their details.""" 
 # Get OAuth2 credentials. 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Create a Report API client. 
 report_service_client 
 = 
 ReportServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Construct the parent resource name for the account. 
 # The parent has the format: accounts/{accountId} 
 parent 
 = 
 f 
 "accounts/ 
 { 
 _ACCOUNT_ID 
 } 
 " 
 # Define the query to select disapproved products. 
 # This query retrieves product information for all disapproved products. 
 # aggregated_reporting_context_status can be one of the following values: 
 # NOT_ELIGIBLE_OR_DISAPPROVED, ELIGIBLE, PENDING, ELIGIBLE_LIMITED, 
 # AGGREGATED_REPORTING_CONTEXT_STATUS_UNSPECIFIED 
 query 
 = 
 ( 
 "SELECT offer_id, id, title, price " 
 "FROM product_view " 
 "WHERE aggregated_reporting_context_status =" 
 "'NOT_ELIGIBLE_OR_DISAPPROVED'" 
 ) 
 # Create the search report request. 
 request 
 = 
 SearchRequest 
 ( 
 parent 
 = 
 parent 
 , 
 query 
 = 
 query 
 ) 
 print 
 ( 
 "Sending search report request for Product View." 
 ) 
 try 
 : 
 # Call the Reports.search API method. 
 response 
 = 
 report_service_client 
 . 
 search 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Received search reports response: " 
 ) 
 # Iterate over all report rows. 
 # The client library automatically handles pagination. 
 for 
 row 
 in 
 response 
 : 
 print 
 ( 
 "Printing data from Product View:" 
 ) 
 print 
 ( 
 row 
 ) 
 # Construct the full product resource name using the product_view.id 
 # (which is the REST ID like "online~en~GB~123") from the report. 
 # The product_view.id from the report is the {product_id} part. 
 product_name 
 = 
 ( 
 f 
 "accounts/ 
 { 
 _ACCOUNT_ID 
 } 
 /products/ 
 { 
 row 
 . 
 product_view 
 . 
 id 
 } 
 " 
 ) 
 # OPTIONAL, get full product details by calling the GetProduct method. 
 print 
 ( 
 "Getting full product details by calling GetProduct method:" 
 ) 
 get_product 
 ( 
 credentials 
 , 
 product_name 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 filter_disapproved_products 
 () 
  
 

Apps_Script

  /** 
  
 * 
  
 Demonstrates 
  
 how 
  
 to 
  
 filter 
  
 disapproved 
  
 products 
  
 using 
  
 the 
  
 Merchant 
  
 API 
  
 Reports 
  
 service 
 . 
  
 */ 
 function 
  
 filterDisapprovedProducts 
 () 
  
 { 
  
 // 
  
 IMPORTANT 
 : 
  
 // 
  
 Enable 
  
 the 
  
 Merchant 
  
 API 
  
 Reports 
  
 sub 
 - 
 API 
  
 Advanced 
  
 Service 
  
 and 
  
 call 
  
 it 
  
 // 
  
 "MerchantApiReports" 
  
 // 
  
 Enable 
  
 the 
  
 Merchant 
  
 API 
  
 Products 
  
 sub 
 - 
 API 
  
 Advanced 
  
 Service 
  
 and 
  
 call 
  
 it 
  
 // 
  
 "MerchantApiProducts" 
  
 // 
  
 Replace 
  
 this 
  
 with 
  
 your 
  
 Merchant 
  
 Center 
  
 ID 
 . 
  
 const 
  
 accountId 
  
 = 
  
 '<INSERT_MERCHANT_CENTER_ID>' 
 ; 
  
 // 
  
 Construct 
  
 the 
  
 parent 
  
 name 
  
 const 
  
 parent 
  
 = 
  
 'accounts/' 
  
 + 
  
 accountId 
 ; 
  
 try 
  
 { 
  
 console 
 . 
 log 
 ( 
 'Sending search Report request' 
 ); 
  
 // 
  
 Set 
  
 pageSize 
  
 to 
  
 the 
  
 maximum 
  
 value 
  
 ( 
 default 
 : 
  
 1000 
 ) 
  
 let 
  
 pageSize 
  
 = 
  
 1000 
 ; 
  
 let 
  
 pageToken 
 ; 
  
 // 
  
 The 
  
 query 
  
 below 
  
 is 
  
 an 
  
 example 
  
 of 
  
 a 
  
 query 
  
 for 
  
 the 
  
 productView 
  
 that 
  
 gets 
  
 product 
  
 informations 
  
 // 
  
 for 
  
 all 
  
 disapproved 
  
 products 
 . 
  
 let 
  
 query 
  
 = 
  
 'SELECT offer_id,' 
  
 + 
  
 'id,' 
  
 + 
  
 'price,' 
  
 + 
  
 'title' 
  
 + 
  
 ' FROM product_view' 
  
 + 
  
 ' WHERE aggregated_reporting_context_status = "NOT_ELIGIBLE_OR_DISAPPROVED"' 
 ; 
  
 // 
  
 Call 
  
 the 
  
 Reports 
 . 
 search 
  
 API 
  
 method 
 . 
  
 Use 
  
 the 
  
 pageToken 
  
 to 
  
 iterate 
  
 through 
  
 // 
  
 all 
  
 pages 
  
 of 
  
 results 
 . 
  
 do 
  
 { 
  
 response 
  
 = 
  
 MerchantApiReports 
 . 
 Accounts 
 . 
 Reports 
 . 
 search 
 ({ 
 query 
 , 
  
 pageSize 
 , 
  
 pageToken 
 }, 
  
 parent 
 ); 
  
 for 
  
 ( 
 const 
  
 reportRow 
  
 of 
  
 response 
 . 
 results 
 ) 
  
 { 
  
 console 
 . 
 log 
 ( 
 "Printing data from Product View:" 
 ); 
  
 console 
 . 
 log 
 ( 
 reportRow 
 ); 
  
 // 
  
 OPTIONALLY 
 , 
  
 you 
  
 can 
  
 get 
  
 the 
  
 full 
  
 product 
  
 details 
  
 by 
  
 calling 
  
 the 
  
 GetProduct 
  
 method 
 . 
  
 let 
  
 productName 
  
 = 
  
 parent 
  
 + 
  
 "/products/" 
  
 + 
  
 reportRow 
 . 
 getProductView 
 () 
 . 
 getId 
 (); 
  
 product 
  
 = 
  
 MerchantApiProducts 
 . 
 Accounts 
 . 
 Products 
 . 
 get 
 ( 
 productName 
 ); 
  
 console 
 . 
 log 
 ( 
 product 
 ); 
  
 } 
  
 pageToken 
  
 = 
  
 response 
 . 
 nextPageToken 
 ; 
  
 } 
  
 while 
  
 ( 
 pageToken 
 ); 
  
 // 
  
 Exits 
  
 when 
  
 there 
  
 is 
  
 no 
  
 next 
  
 page 
  
 token 
 . 
  
 } 
  
 catch 
  
 ( 
 e 
 ) 
  
 { 
  
 console 
 . 
 log 
 ( 
 'ERROR!' 
 ); 
  
 console 
 . 
 log 
 ( 
 'Error message:' 
  
 + 
  
 e 
 . 
 message 
 ); 
  
 } 
 } 
  
 

cURL

  curl -X POST "https://merchantapi.googleapis.com/reports/v1/accounts/ {ACCOUNT_ID} 
/reports:search" \ 
 -H "Authorization: Bearer <API_TOKEN>" \ 
 -H "Content-Type: application/json" \ 
 -d '{ 
 "query": "SELECT offer_id, id, title FROM product_view WHERE aggregated_reporting_context_status =  \"NOT_ELIGIBLE_OR_DISAPPROVED\"" 
 }' 
 
Design a Mobile Site
View Site in Mobile | Classic
Share by: