Delete a product input

Merchant API code sample to delete a product input.

CSharp

  // Copyright 2025 Google LLC 
 // 
 // Licensed under the Apache License, Version 2.0 (the "License"); 
 // you may not use this file except in compliance with the License. 
 // You may obtain a copy of the License at 
 // 
 //     https://www.apache.org/licenses/LICENSE-2.0 
 // 
 // Unless required by applicable law or agreed to in writing, software 
 // distributed under the License is distributed on an "AS IS" BASIS, 
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 // See the License for the specific language governing permissions and 
 // limitations under the License. 
 using 
  
 Google.Apis.Auth.OAuth2 
 ; 
 using 
  
 Google.Shopping.Merchant.Products.V1 
 ; 
 using 
  
 System 
 ; 
 using 
  
 static 
  
 MerchantApi 
 . 
 Authenticator 
 ; 
 namespace 
  
 MerchantApi 
 { 
  
 /// <summary> 
  
 /// This class demonstrates how to delete a product input for a given Merchant Center account. 
  
 /// </summary> 
  
 public 
  
 class 
  
 DeleteProductInputSample 
  
 { 
  
 // Deletes a product input from a specified data source. 
  
 public 
  
 void 
  
 DeleteProductInput 
 ( 
 string 
  
 merchantId 
 , 
  
 string 
  
 productId 
 , 
  
 string 
  
 dataSource 
 ) 
  
 { 
  
 Console 
 . 
 WriteLine 
 ( 
 "=================================================================" 
 ); 
  
 Console 
 . 
 WriteLine 
 ( 
 "Deleting a ProductInput from a data source..." 
 ); 
  
 Console 
 . 
 WriteLine 
 ( 
 "=================================================================" 
 ); 
  
 // Authenticate using either OAuth or a service account. 
  
 ICredential 
  
 auth 
  
 = 
  
 Authenticator 
 . 
 Authenticate 
 ( 
  
 MerchantConfig 
 . 
 Load 
 (), 
  
 ProductsServiceClient 
 . 
 DefaultScopes 
 [ 
 0 
 ]); 
  
 // Create the ProductInputsServiceClient. 
  
 var 
  
 productInputsServiceClient 
  
 = 
  
 new 
  
 ProductInputsServiceClientBuilder 
  
 { 
  
 Credential 
  
 = 
  
 auth 
  
 }. 
 Build 
 (); 
  
 // Create the product name to identify the product. 
  
 string 
  
 name 
  
 = 
  
 ProductInputName 
 . 
 FromAccountProductinput 
 ( 
 merchantId 
 , 
  
 productId 
 ). 
 ToString 
 (); 
  
 // Create the request to delete the product input. 
  
 DeleteProductInputRequest 
  
 request 
  
 = 
  
 new 
  
 DeleteProductInputRequest 
  
 { 
  
 Name 
  
 = 
  
 name 
 , 
  
 DataSource 
  
 = 
  
 dataSource 
  
 }; 
  
 try 
  
 { 
  
 Console 
 . 
 WriteLine 
 ( 
 "Sending deleteProductInput request..." 
 ); 
  
 // The call returns no response on success. 
  
 productInputsServiceClient 
 . 
 DeleteProductInput 
 ( 
 request 
 ); 
  
 Console 
 . 
 WriteLine 
 ( 
  
 "Delete successful, note that it may take a few minutes for the delete to update in the system. " 
  
 + 
  
 "If you make a products.get or products.list request before a few minutes have passed, " 
  
 + 
  
 "the old product data may be returned." 
 ); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 Console 
 . 
 WriteLine 
 ( 
 e 
 . 
 Message 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 Main 
 ( 
 string 
 [] 
  
 args 
 ) 
  
 { 
  
 MerchantConfig 
  
 config 
  
 = 
  
 MerchantConfig 
 . 
 Load 
 (); 
  
 string 
  
 merchantId 
  
 = 
  
 config 
 . 
 MerchantId 
 . 
 Value 
 . 
 ToString 
 (); 
  
 // An ID assigned to a product by Google. In the format: 
  
 // channel~contentLanguage~feedLabel~offerId 
  
 string 
  
 productId 
  
 = 
  
 "online~en~US~sku123" 
 ; 
  
 // The name of the dataSource from which to delete the product. 
  
 // If it is a primary feed, this will delete the product completely. 
  
 // If it's a supplemental feed, it will only delete the product information 
  
 // from that feed, but the product will still be available from the primary feed. 
  
 // Replace {INSERT_DATASOURCE_ID} with your actual data source ID. 
  
 string 
  
 dataSourceId 
  
 = 
  
 "{INSERT_DATASOURCE_ID}" 
 ; 
  
 string 
  
 dataSource 
  
 = 
  
 $"accounts/{config.MerchantId}/dataSources/{dataSourceId}" 
 ; 
  
 var 
  
 sample 
  
 = 
  
 new 
  
 DeleteProductInputSample 
 (); 
  
 sample 
 . 
 DeleteProductInput 
 ( 
 merchantId 
 , 
  
 productId 
 , 
  
 dataSource 
 ); 
  
 } 
  
 } 
 } 
  
 

Java

  // Copyright 2024 Google LLC 
 // 
 // Licensed under the Apache License, Version 2.0 (the "License"); 
 // you may not use this file except in compliance with the License. 
 // You may obtain a copy of the License at 
 // 
 //     https://www.apache.org/licenses/LICENSE-2.0 
 // 
 // Unless required by applicable law or agreed to in writing, software 
 // distributed under the License is distributed on an "AS IS" BASIS, 
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 // See the License for the specific language governing permissions and 
 // limitations under the License. 
 package 
  
 shopping.merchant.samples.products.v1 
 ; 
 import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.DeleteProductInputRequest 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductInputName 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductInputsServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.products.v1.ProductInputsServiceSettings 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to delete a product for a given Merchant Center account */ 
 public 
  
 class 
 DeleteProductInputSample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 deleteProductInput 
 ( 
 Config 
  
 config 
 , 
  
 String 
  
 productId 
 , 
  
 String 
  
 dataSource 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // Obtains OAuth token based on the user's configuration. 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 // Creates service settings using the credentials retrieved above. 
  
 ProductInputsServiceSettings 
  
 productInputsServiceSettings 
  
 = 
  
 ProductInputsServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates product name to identify product. 
  
 String 
  
 name 
  
 = 
  
 ProductInputName 
 . 
 newBuilder 
 () 
  
 . 
 setAccount 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()) 
  
 . 
 setProductinput 
 ( 
 productId 
 ) 
  
 . 
 build 
 () 
  
 . 
 toString 
 (); 
  
 // Calls the API and catches and prints any network failures/errors. 
  
 try 
  
 ( 
 ProductInputsServiceClient 
  
 productInputsServiceClient 
  
 = 
  
 ProductInputsServiceClient 
 . 
 create 
 ( 
 productInputsServiceSettings 
 )) 
  
 { 
  
 DeleteProductInputRequest 
  
 request 
  
 = 
  
 DeleteProductInputRequest 
 . 
 newBuilder 
 (). 
 setName 
 ( 
 name 
 ). 
 setDataSource 
 ( 
 dataSource 
 ). 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending deleteProductInput request" 
 ); 
  
 productInputsServiceClient 
 . 
 deleteProductInput 
 ( 
 request 
 ); 
  
 // no response returned on success 
  
 System 
 . 
 out 
 . 
 println 
 ( 
  
 "Delete successful, note that it may take a few minutes for the delete to update in" 
  
 + 
  
 " the system. If you make a products.get or products.list request before a few" 
  
 + 
  
 " minutes have passed, the old product data may be returned." 
 ); 
  
 } 
  
 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 
  
 // contentLanguage~feedLabel~offerId 
  
 String 
  
 productId 
  
 = 
  
 "online~en~label~sku123" 
 ; 
  
 // The name of the dataSource from which to delete the product. If it is a primary feed, this 
  
 // will delete the product completely. If it's a supplemental feed, it will only delete the 
  
 // product information from that feed, but the product will still be available from the primary 
  
 // feed. 
  
 String 
  
 dataSource 
  
 = 
  
 "accounts/{account}/dataSources/{dataSource}" 
 ; 
  
 deleteProductInput 
 ( 
 config 
 , 
  
 productId 
 , 
  
 dataSource 
 ); 
  
 } 
 } 
  
 

Node.js

  // Copyright 2025 Google LLC 
 // 
 // Licensed under the Apache License, Version 2.0 (the "License"); 
 // you may not use this file except in compliance with the License. 
 // You may obtain a copy of the License at 
 // 
 //     https://www.apache.org/licenses/LICENSE-2.0 
 // 
 // Unless required by applicable law or agreed to in writing, software 
 // distributed under the License is distributed on an "AS IS" BASIS, 
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 // See the License for the specific language governing permissions and 
 // limitations under the License. 
 'use strict' 
 ; 
 const 
  
 fs 
  
 = 
  
 require 
 ( 
 'fs' 
 ); 
 const 
  
 authUtils 
  
 = 
  
 require 
 ( 
 '../../authentication/authenticate.js' 
 ); 
 const 
  
 { 
  
 ProductInputsServiceClient 
 , 
 } 
  
 = 
  
 require 
 ( 
 '@google-shopping/products' 
 ). 
 v1 
 ; 
 /** 
 * This class demonstrates how to delete a product input for a given 
 * Merchant Center account. 
 * @param {!object} config - The configuration object. 
 * @param {string} productId - The ID of the product input to delete. 
 * @param {string} dataSource - The name of the data source from which to delete the product input. 
 */ 
 async 
  
 function 
  
 deleteProductInput 
 ( 
 config 
 , 
  
 productId 
 , 
  
 dataSource 
 ) 
  
 { 
  
 // Read merchant_id from merchant-info.json. 
  
 const 
  
 merchantInfo 
  
 = 
  
 JSON 
 . 
 parse 
 ( 
  
 fs 
 . 
 readFileSync 
 ( 
 config 
 . 
 merchantInfoFile 
 , 
  
 'utf8' 
 ) 
  
 ); 
  
 const 
  
 merchantId 
  
 = 
  
 merchantInfo 
 . 
 merchantId 
 ; 
  
 // Construct the fully qualified product input name. 
  
 // Format: accounts/{account}/productInputs/{productInput} 
  
 const 
  
 name 
  
 = 
  
 `accounts/ 
 ${ 
 merchantId 
 } 
 /productInputs/ 
 ${ 
 productId 
 } 
 ` 
 ; 
  
 // Get credentials. 
  
 const 
  
 authClient 
  
 = 
  
 await 
  
 authUtils 
 . 
 getOrGenerateUserCredentials 
 (); 
  
 // Create options object for the client. 
  
 const 
  
 options 
  
 = 
  
 { 
 authClient 
 : 
  
 authClient 
 }; 
  
 // Create the ProductInputsServiceClient. 
  
 const 
  
 productInputsClient 
  
 = 
  
 new 
  
 ProductInputsServiceClient 
 ( 
 options 
 ); 
  
 // Construct the request object. 
  
 const 
  
 request 
  
 = 
  
 { 
  
 name 
 : 
  
 name 
 , 
  
 dataSource 
 : 
  
 dataSource 
 , 
  
 }; 
  
 try 
  
 { 
  
 console 
 . 
 log 
 ( 
 'Sending deleteProductInput request' 
 ); 
  
 // Call the API to delete the product input. 
  
 // No response is returned on success. 
  
 await 
  
 productInputsClient 
 . 
 deleteProductInput 
 ( 
 request 
 ); 
  
 console 
 . 
 log 
 ( 
  
 'Delete successful, note that it may take a few minutes for the delete to update in' 
  
 + 
  
 ' the system. If you make a products.get or products.list request before a few' 
  
 + 
  
 ' minutes have passed, the old product data may be returned.' 
  
 ); 
  
 } 
  
 catch 
  
 ( 
 error 
 ) 
  
 { 
  
 console 
 . 
 error 
 ( 
 error 
 . 
 message 
 ); 
  
 } 
 } 
 /** 
 * Main function to call the deleteProductInput function. 
 */ 
 async 
  
 function 
  
 main 
 () 
  
 { 
  
 const 
  
 config 
  
 = 
  
 authUtils 
 . 
 getConfig 
 (); 
  
 // An ID assigned to a product input by Google. In the format 
  
 // contentLanguage~feedLabel~offerId 
  
 const 
  
 productId 
  
 = 
  
 'en~label~sku123' 
 ; 
  
 const 
  
 merchantInfo 
  
 = 
  
 JSON 
 . 
 parse 
 ( 
  
 fs 
 . 
 readFileSync 
 ( 
 config 
 . 
 merchantInfoFile 
 , 
  
 'utf8' 
 ) 
  
 ); 
  
 const 
  
 merchantId 
  
 = 
  
 merchantInfo 
 . 
 merchantId 
 ; 
  
 // The name of the dataSource from which to delete the product input. 
  
 // If it is a primary feed, this will delete the product completely. 
  
 // If it's a supplemental feed, it will only delete the product information 
  
 // from that feed, but the product will still be available from the primary feed. 
  
 // Format: accounts/{account}/dataSources/{dataSource} 
  
 // Replace {dataSource} with the actual ID of your data source. 
  
 const 
  
 dataSource 
  
 = 
  
 `accounts/ 
 ${ 
 merchantId 
 } 
 /dataSources/{dataSource}` 
 ; 
  
 await 
  
 deleteProductInput 
 ( 
 config 
 , 
  
 productId 
 , 
  
 dataSource 
 ); 
 } 
 main 
 (); 
  
 

PHP

 < ?php 
 /** 
 * Copyright 2024 Google LLC 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *     https://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 
 require_once __DIR__ . '/../../../vendor/autoload.php'; 
 require_once __DIR__ . '/../../Authentication/Authentication.php'; 
 require_once __DIR__ . '/../../Authentication/Config.php'; 
 use Google\ApiCore\ApiException; 
 use Google\Auth\CredentialsLoader; 
 use Google\Shopping\Merchant\Products\V1\Client\ProductInputsServiceClient; 
 use Google\Shopping\Merchant\Products\V1\DeleteProductInputRequest; 
 use Google\Shopping\Merchant\Products\V1\ProductInputName; 
 /** 
 * This class demonstrates how to delete a productinput for a given Merchant Center 
 * account. 
 */ 
 class DeleteProductInput 
 { 
 // ENSURE you fill in the product and datasource ID for the sample to work. 
 // An ID assigned to a product by Google: 
 // In the format `contentLanguage~feedLabel~offerId` 
 private const PRODUCT = 'INSERT_PRODUCT_ID_HERE'; 
 private const DATASOURCE = 'INSERT_DATASOURCE_ID_HERE'; 
 /** 
 * Deletes a product input to your Merchant Center account. 
 * 
 * @param array  $config 
 *      The configuration data used for authentication and getting the 
 *      acccount ID. 
 * @param string $product 
 *      The product ID to delete. 
 *      Format: `accounts/{account}/products/{productId}`. 
 * @param string $dataSource 
 *      The primary or supplemental product data source name that owns the 
 *      product. 
 *      Format: `accounts/{account}/dataSources/{datasource}`. 
 * 
 * @return void 
 */ 
 public static function deleteProductInputSample( 
 $config, $product, $dataSource 
 ): void { 
 // Obtains OAuth token based on the user's configuration. 
 $credentials = Authentication::useServiceAccountOrTokenFile(); 
 // Creates service settings using the credentials retrieved above. 
 $options = ['credentials' => $credentials]; 
 $productInputsServiceClient = new ProductInputsServiceClient($options); 
 // Calls the API and catches and prints any network failures/errors. 
 try { 
 $request = new DeleteProductInputRequest( 
 [ 
 'name' => $product, 
 'data_source' => $dataSource 
 ] 
 ); 
 echo "Sending deleteProductInput request\n"; 
 $productInputsServiceClient->deleteProductInput($request); 
 echo "Delete successful, note that it may take a few minutes for the " 
 . "delete to update in the system. If you make a products.get or " 
 . "products.list request before a few  minutes have passed, the old " 
 . "product data may be returned.\n"; 
 } catch (ApiException $e) { 
 echo "An error has occurred: \n"; 
 echo $e->getMessage() . "\n"; 
 } 
 } 
 /** 
 * Helper to execute the sample. 
 * 
 * @return void 
 */ 
 public function callSample(): void 
 { 
 $config = Config::generateConfig(); 
 // The productID variable is defined at the top of the file. 
 $product = ProductInputsServiceClient::productInputName( 
 $config['accountId'], 
 self::PRODUCT 
 ); 
 // The name of the dataSource from which to delete the product. 
 $dataSource = sprintf( 
 'accounts/%s/dataSources/%s', 
 $config['accountId'], 
 self::DATASOURCE 
 ); 
 self::deleteProductInputSample($config, $product, $dataSource); 
 } 
 } 
 // Run the script. 
 $sample = new DeleteProductInput(); 
 $sample->callSample();  
 
 

Python

  # -*- coding: utf-8 -*- 
 # Copyright 2024 Google LLC 
 # 
 # Licensed under the Apache License, Version 2.0 (the "License"); 
 # you may not use this file except in compliance with the License. 
 # You may obtain a copy of the License at 
 # 
 #     http://www.apache.org/licenses/LICENSE-2.0 
 # 
 # Unless required by applicable law or agreed to in writing, software 
 # distributed under the License is distributed on an "AS IS" BASIS, 
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 # See the License for the specific language governing permissions and 
 # limitations under the License. 
 """A module to delete a Product Input.""" 
 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 
 () 
 # ENSURE you fill in the product ID and data source for the 
 # sample to work. 
 # In the format of `contentLanguage~feedLabel~offerId` 
 _PRODUCT 
 = 
 "[INSERT_PRODUCT_HERE]" 
 _DATA_SOURCE 
 = 
 "[INSERT_DATA_SOURCE_HERE]" 
 _NAME 
 = 
 f 
 "accounts/ 
 { 
 _ACCOUNT 
 } 
 /productInputs/ 
 { 
 _PRODUCT 
 } 
 " 
 _DATA_SOURCE_NAME 
 = 
 f 
 "accounts/ 
 { 
 _ACCOUNT 
 } 
 /dataSources/ 
 { 
 _DATA_SOURCE 
 } 
 " 
 def 
  
 delete_product_input 
 (): 
  
 """Deletes the specified `ProductInput` resource.""" 
 # Gets OAuth Credentials. 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Creates a client. 
 client 
 = 
 merchant_products_v1 
 . 
 ProductInputsServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Creates the request. 
 request 
 = 
 merchant_products_v1 
 . 
 DeleteProductInputRequest 
 ( 
 name 
 = 
 _NAME 
 , 
 data_source 
 = 
 _DATA_SOURCE_NAME 
 ) 
 # Makes the request and catch and print any error messages. 
 try 
 : 
 client 
 . 
 delete_product_input 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Deletion successful" 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 "Deletion failed" 
 ) 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 delete_product_input 
 () 
  
 
Design a Mobile Site
View Site in Mobile | Classic
Share by: