Delete a product

Delete a product.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


import (

	vision ""
	visionpb ""

// deleteProduct deletes a product.
func deleteProduct(w io.Writer, projectID string, location string, productID string) error {
	ctx := context.Background()
	c, err := vision.NewProductSearchClient(ctx)
	if err != nil {
		return fmt.Errorf("NewProductSearchClient: %v", err)
	defer c.Close()

	req := &visionpb.DeleteProductRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/products/%s", projectID, location, productID),

	if err = c.DeleteProduct(ctx, req); err != nil {
		return fmt.Errorf("NewProductSearchClient: %v", err)

	fmt.Fprintf(w, "Product deleted.\n")

	return nil


 * Delete the product and all its reference images.
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @throws IOException - on I/O errors.
public static void deleteProduct(String projectId, String computeRegion, String productId)
    throws IOException {
  try (ProductSearchClient client = ProductSearchClient.create()) {

    // Get the full path of the product.
    String formattedName =
        ProductSearchClient.formatProductName(projectId, computeRegion, productId);

    // Delete a product.
    System.out.println("Product deleted.");


// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');

// Creates a client
const client = new vision.ProductSearchClient();

async function deleteProduct() {
   * TODO(developer): Uncomment the following line before running the sample.
  // const projectId = 'Your Google Cloud project Id';
  // const location = 'A compute region name';
  // const productId = 'Id of the product';

  // Resource path that represents full path to the product.
  const productPath = client.productPath(projectId, location, productId);

  await client.deleteProduct({name: productPath});
  console.log('Product deleted.');


from import vision
from google.protobuf import field_mask_pb2 as field_mask

def delete_product(project_id, location, product_id):
    """Delete the product and all its reference images.
        project_id: Id of the project.
        location: A compute region name.
        product_id: Id of the product.
    client = vision.ProductSearchClient()

    # Get the full path of the product.
    product_path = client.product_path(
        project=project_id, location=location, product=product_id)

    # Delete a product.
    print('Product deleted.')

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.