Merchant API code sample to delete a product input.

### C#

    // 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:
                // contentLanguage~feedLabel~offerId
                string productId = "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);
            }
        }
    }

### Go

    // 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 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 v1


    import (
    	"context"
    	"fmt"
    	"log"

    	"cloud.google.com/go/shopping/merchant/products/apiv1/productspb"

    	products "cloud.google.com/go/shopping/merchant/products/apiv1"

    	"google.golang.org/api/option"
    	"github.com/google/merchant-api-samples/go/collection"
    	"github.com/google/merchant-api-samples/go/examples/googleauth"
    )

    // These are all placeholder values. Please fill in your own details.
    const accountIDForDelete = "1234567890"

    // The ID of the product. In the format of `contentLanguage~feedLabel~offerId`.
    const productIDForDelete = "en~label~sku123"

    // The data source from which to delete the product.
    // Format: `accounts/{account}/dataSources/{dataSource}`
    const dataSourceForDelete = "accounts/1234567890/dataSources/1234567890"

    type deleteProductInputSample struct{}

    func init() {
    	if err := collection.Add("products.productinputs.v1.delete_product_input", &deleteProductInputSample{}); err != nil {
    		log.Fatalf("could not add example: %v", err)
    	}
    }

    func (s *deleteProductInputSample) Description() string {
    	return "This sample demonstrates how to delete a product input"
    }

    func (s *deleteProductInputSample) Execute() error {
    	ctx := context.Background()

    	// Authenticates with Google.
    	tokenSource, err := googleauth.AuthWithGoogle(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to authenticate: %w", err)
    	}

    	// Creates a new product inputs client.
    	productInputsClient, err := products.NewProductInputsClient(ctx, option.WithTokenSource(tokenSource))
    	if err != nil {
    		return fmt.Errorf("could not create product inputs client: %w", err)
    	}
    	defer productInputsClient.Close()

    	// The name of the product to delete.
    	// Format: `accounts/{account}/productinputs/{productinput}`
    	name := fmt.Sprintf("accounts/%s/productInputs/%s", accountIDForDelete, productIDForDelete)

    	// Creates the request to delete the product input.
    	req := &productspb.DeleteProductInputRequest{
    		Name:       name,
    		DataSource: dataSourceForDelete,
    	}

    	fmt.Println("Sending deleteProductInput request")
    	// The DeleteProductInput method doesn't return a response upon success.
    	err = productInputsClient.DeleteProductInput(ctx, req)
    	if err != nil {
    		return fmt.Errorf("could not delete product input: %w", err)
    	}

    	fmt.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.")
    	return nil
    }


### 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.");
        }
      }

      public static void main(String[] args) throws Exception {
        Config config = Config.load();
        // An ID assigned to a product input by Google. In the format
        // contentLanguage~feedLabel~offerId
        String productId = "en~GB~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


    def delete_product_input(account_id: str, product_id: str, data_source: str):
      """Deletes the specified `ProductInput` resource.

      Args:
        account_id: The Merchant Center account ID.
        product_id: The ID of the product input to delete, in the format
          `contentLanguage~feedLabel~offerId`.
        data_source: The resource name of the data source from which to delete the
          product.
      """

      # Gets OAuth Credentials.
      credentials = generate_user_credentials.main()

      # Creates a client.
      client = merchant_products_v1.ProductInputsServiceClient(
          credentials=credentials
      )

      name = f"accounts/{account_id}/productInputs/{product_id}"

      # Creates the request.
      request = merchant_products_v1.DeleteProductInputRequest(
          name=name, data_source=data_source
      )

      # 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)
        raise


    if __name__ == "__main__":
      # Retrieves the Merchant Center account ID from the configuration file.
      merchant_account_id = 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`
      target_product = "[INSERT_PRODUCT_HERE]"
      target_data_source = (
          f"accounts/{merchant_account_id}/dataSources/[INSERT_DATA_SOURCE_HERE]"
      )

      delete_product_input(
          merchant_account_id, target_product, target_data_source
      )