Deleting resources

You can delete reference image, product, or product set resources created by the API.

Deleting a reference image

You can delete a reference image associated with a product.

Command-line

To delete a single image, send a DELETE request to the following URI.

  • Replace project-id with the id of your Google Cloud Platform (GCP) project.

  • Replace location-id with a valid location identifier. Valid location identifiers are: us-west1, us-east1, europe-west1, and asia-east1.

  • Replace product-id with the id for the product that is associated with the image.

  • Replace image-id with the id of the image to delete.

DELETE https://vision.googleapis.com/v1p3beta1/projects/project-id/locations/location-id/products/product-id/referenceImages/image-id

The images are marked for deletion, but will remain in the product until the next time it is indexed.

The actual image files in Google Cloud Storage are NOT deleted by this operation. Only the reference to the image is removed from the product.

Python

from google.cloud import vision_v1p3beta1 as vision

def delete_reference_image(
        project_id, location, product_id, reference_image_id):
    """Delete a reference image.
    Args:
        project_id: Id of the project.
        location: A compute region name.
        product_id: Id of the product.
        reference_image_id: Id of the reference image.
    """
    client = vision.ProductSearchClient()

    # Get the full path of the reference image.
    reference_image_path = client.reference_image_path(
        project=project_id, location=location, product=product_id,
        reference_image=reference_image_id)

    # Delete the reference image.
    client.delete_reference_image(name=reference_image_path)
    print('Reference image deleted from product.')

Java

/**
 * Delete a reference image.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param referenceImageId - Id of the image.
 * @throws IOException - on I/O errors.
 */
public static void deleteReferenceImage(
    String projectId, String computeRegion, String productId, String referenceImageId)
    throws IOException {
  ProductSearchClient client = ProductSearchClient.create();

  // Get the full path of the reference image.
  ReferenceImageName referenceImagePath =
      ReferenceImageName.of(projectId, computeRegion, productId, referenceImageId);

  // Delete the reference image.
  client.deleteReferenceImage(referenceImagePath.toString());
  System.out.println("Reference image deleted from product.");
}

Node.js

const vision = require('@google-cloud/vision').v1p3beta1;

const client = new vision.ProductSearchClient();

/**
 * 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';
// const referenceImageId = 'Id of the reference image';

const formattedName = client.referenceImagePath(
  projectId,
  location,
  productId,
  referenceImageId
);

const request = {
  name: formattedName,
};

client
  .deleteReferenceImage(request)
  .then(() => {
    console.log(`Reference image deleted from product.`);
  })
  .catch(err => {
    console.log(err);
  });

Deleting a product

You can delete a product associated with a specific project.

Deleting a Product causes its child images to be deleted.

Command-line

To delete a single product, send a DELETE request to the following URI.

  • Replace project-id with the id of your Google Cloud Platform (GCP) project.

  • Replace location-id with a valid location identifier. Valid location identifiers are: us-west1, us-east1, europe-west1, and asia-east1.

  • Replace product-id with the id for the product that is associated with the image.

DELETE https://vision.googleapis.com/v1p3beta1/projects/project-id/locations/location-id/products/product-id

Python

from google.cloud import vision_v1p3beta1 as vision

def delete_product(project_id, location, product_id):
    """Delete the product and all its reference images.
    Args:
        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.
    client.delete_product(name=product_path)
    print('Product deleted.')

Java

/**
 * 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 {
  ProductSearchClient client = ProductSearchClient.create();

  // Get the full path of the product.
  ProductName productPath = ProductName.of(projectId, computeRegion, productId);

  // Delete a product.
  client.deleteProduct(productPath);

  System.out.println("Product deleted.");
}

Node.js

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

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

/**
 * 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);

client
  .deleteProduct({name: productPath})
  .then(() => {
    console.log('Product deleted.');
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Deleting a product set

You can also delete an entire product set and all the images contained in it.

Deleting a product set immediately removes the product set from results. You do not need to wait for the next index for the change to take effect.

The actual image files in Google Cloud Storage are NOT deleted by this operation. ReferenceImage resources created by the API are not removed.

Command-line

To delete a product set and all of the images it contains, send a DELETE request to the following URI.

  • Replace project-id with the id of your Google Cloud Platform (GCP) project.

  • Replace location-id with a valid location identifier. Valid location identifiers are: us-west1, us-east1, europe-west1, and asia-east1.

  • Replace product-set-id with the id for the product that is associated with the image.

DELETE https://vision.googleapis.com/v1p3beta1/projects/project-id/locations/location-id/productSets/product-set-id

Python

from google.cloud import vision_v1p3beta1 as vision

def delete_product_set(project_id, location, product_set_id):
    """Delete a product set.
    Args:
        project_id: Id of the project.
        location: A compute region name.
        product_set_id: Id of the product set.
    """
    client = vision.ProductSearchClient()

    # Get the full path of the product set.
    product_set_path = client.product_set_path(
        project=project_id, location=location,
        product_set=product_set_id)

    # Delete the product set.
    client.delete_product_set(name=product_set_path)
    print('Product set deleted.')

Java

/**
 * Delete a product set.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productSetId - Id of the product set.
 * @throws IOException - on I/O errors.
 */
public static void deleteProductSet(
    String projectId, String computeRegion, String productSetId) throws IOException {
  ProductSearchClient client = ProductSearchClient.create();

  // Get the full path of the product set.
  ProductSetName productSetPath = ProductSetName.of(projectId, computeRegion, productSetId);

  // Delete the product set.
  client.deleteProductSet(productSetPath.toString());

  System.out.println(String.format("Product set deleted"));
}

Node.js

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

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

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

// Resource path that represents full path to the product set.
const productSetPath = client.productSetPath(
  projectId,
  location,
  productSetId
);

client
  .deleteProductSet({name: productSetPath})
  .then(() => {
    console.log('Product set deleted.');
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Vision API
Need help? Visit our support page.