Getting and listing resources

At any time you can list and get any product set, product, or reference image resources you have.

Listing product sets

You can have multiple product sets. This section describes how to retrieve a list of all your product sets.

Command-line

To get a list of all of the product sets for a GCP project, send a 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.

GET https://vision.googleapis.com/v1p3beta1/projects/project-id/locations/location-id/productSets

Python

from google.cloud import vision_v1p3beta1 as vision

def list_product_sets(project_id, location):
    """List all product sets.
    Args:
        project_id: Id of the project.
        location: A compute region name.
    """
    client = vision.ProductSearchClient()

    # A resource that represents Google Cloud Platform location.
    location_path = client.location_path(
        project=project_id, location=location)

    # List all the product sets available in the region.
    product_sets = client.list_product_sets(parent=location_path)

    # Display the product set information.
    for product_set in product_sets:
        print('Product set name: {}'.format(product_set.name))
        print('Product set id: {}'.format(product_set.name.split('/')[-1]))
        print('Product set display name: {}'.format(product_set.display_name))
        print('Product set index time:')
        print('  seconds: {}'.format(product_set.index_time.seconds))
        print('  nanos: {}\n'.format(product_set.index_time.nanos))

Java

/**
 * List all product sets
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @throws IOException - on I/O errors.
 */
public static void listProductSets(String projectId, String computeRegion) throws IOException {
  ProductSearchClient client = ProductSearchClient.create();
  // A resource that represents Google Cloud Platform location.
  LocationName projectLocation = LocationName.of(projectId, computeRegion);
  // List all the product sets available in the region.
  for (ProductSet productSet : client.listProductSets(projectLocation).iterateAll()) {
    // Display the product set information
    System.out.println(String.format("Product set name: %s", productSet.getName()));
    System.out.println(
        String.format(
            "Product set id: %s",
            productSet.getName().substring(productSet.getName().lastIndexOf('/') + 1)));
    System.out.println(
        String.format("Product set display name: %s", productSet.getDisplayName()));
    System.out.println("Product set index time:");
    System.out.println(String.format("\tseconds: %s", productSet.getIndexTime().getSeconds()));
    System.out.println(String.format("\tnanos: %s", productSet.getIndexTime().getNanos()));
  }

}

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';

// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);

client
  .listProductSets({parent: locationPath})
  .then(results => {
    const productSets = results[0];
    productSets.forEach(productSet => {
      console.log(`Product Set name: ${productSet.name}`);
      console.log(`Product Set display name: ${productSet.displayName}`);
    });
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Getting a single product set

You can get a single product set to use or modify.

Command-line

To get the information for a product set, send a 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 set that you want to get.

GET 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 get_product_set(project_id, location, product_set_id):
    """Get info about the 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)

    # Get complete detail of the product set.
    product_set = client.get_product_set(name=product_set_path)

    # Display the product set information.
    print('Product set name: {}'.format(product_set.name))
    print('Product set id: {}'.format(product_set.name.split('/')[-1]))
    print('Product set display name: {}'.format(product_set.display_name))
    print('Product set index time:')
    print('  seconds: {}'.format(product_set.index_time.seconds))
    print('  nanos: {}'.format(product_set.index_time.nanos))

Java

/**
 * Get info about the 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 getProductSet(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);

  // Get complete detail of the product set.
  ProductSet productSet = client.getProductSet(productSetPath);

  // Display the product set information
  System.out.println(String.format("Product set name: %s", productSet.getName()));
  System.out.println(
      String.format(
          "Product set id: %s",
          productSet.getName().substring(productSet.getName().lastIndexOf('/') + 1)));
  System.out.println(String.format("Product set display name: %s", productSet.getDisplayName()));
  System.out.println("Product set index time:");
  System.out.println(String.format("\tseconds: %s", productSet.getIndexTime().getSeconds()));
  System.out.println(String.format("\tnanos: %s", productSet.getIndexTime().getNanos()));
}

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 Google Cloud Platform location.
const productSetPath = client.productSetPath(
  projectId,
  location,
  productSetId
);

client
  .getProductSet({name: productSetPath})
  .then(results => {
    const productSet = results[0];
    console.log(`Product Set name: ${productSet.name}`);
    console.log(`Product Set display name: ${productSet.displayName}`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Listing products

You may wish to view all products in a Google Cloud Platform project. The following example shows how to list products in a given project.

Command-line

To get a list of all of the products for a GCP project, send a 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.

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

To list the products for a product set, send a 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 set that you is associated with the products that you want to list.

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

Python

from google.cloud import vision_v1p3beta1 as vision

def list_products(project_id, location):
    """List all products.
    Args:
        project_id: Id of the project.
        location: A compute region name.
    """
    client = vision.ProductSearchClient()

    # A resource that represents Google Cloud Platform location.
    location_path = client.location_path(project=project_id, location=location)

    # List all the products available in the region.
    products = client.list_products(parent=location_path)

    # Display the product information.
    for product in products:
        print('Product name: {}'.format(product.name))
        print('Product id: {}'.format(product.name.split('/')[-1]))
        print('Product display name: {}'.format(product.display_name))
        print('Product description: {}'.format(product.description))
        print('Product category: {}'.format(product.product_category))
        print('Product labels: {}\n'.format(product.product_labels))

Java

/**
 * List all products.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @throws IOException - on I/O errors.
 */
public static void listProducts(String projectId, String computeRegion) throws IOException {
  ProductSearchClient client = ProductSearchClient.create();

  // A resource that represents Google Cloud Platform location.
  LocationName projectLocation = LocationName.of(projectId, computeRegion);

  // List all the products available in the region.
  for (Product product : client.listProducts(projectLocation).iterateAll()) {
    // Display the product information
    System.out.println(String.format("\nProduct name: %s", product.getName()));
    System.out.println(
        String.format(
              "Product id: %s",
                  product.getName().substring(product.getName().lastIndexOf('/') + 1)));
    System.out.println(String.format("Product display name: %s", product.getDisplayName()));
    System.out.println(String.format("Product category: %s", product.getProductCategory()));
    System.out.println("Product labels:");
    System.out.println(
        String.format("Product labels: %s", product.getProductLabelsList().toString()));
  }
}

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';

// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);

client
  .listProducts({parent: locationPath})
  .then(results => {
    const products = results[0];
    products.forEach(product => {
      console.log(`Product name: ${product.name}`);
      console.log(`Product id: ${product.name.split('/').pop()}`);
      console.log(`Product display name: ${product.displayName}`);
      console.log(`Product description: ${product.description}`);
      console.log(`Product category: ${product.productCategory}`);
      if (product.productLabels.length) {
        console.log(`Product labels:`);
        product.productLabels.forEach(productLabel => {
          console.log(`${productLabel.key}: ${productLabel.value}`);
        });
      }
    });
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Getting a single product

You can also get a single product to use or modify.

Command-line

To get the information for a single product, send a 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 you want to get.

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

Python

from google.cloud import vision_v1p3beta1 as vision

def get_product(project_id, location, product_id):
    """Get information about a product.
    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)

    # Get complete detail of the product.
    product = client.get_product(name=product_path)

    # Display the product information.
    print('Product name: {}'.format(product.name))
    print('Product id: {}'.format(product.name.split('/')[-1]))
    print('Product display name: {}'.format(product.display_name))
    print('Product description: {}'.format(product.description))
    print('Product category: {}'.format(product.product_category))
    print('Product labels: {}'.format(product.product_labels))

Java

/**
 * Get information about a product.
 *
 * @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 getProduct(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);

  // Get complete detail of the product.
  Product product = client.getProduct(productPath.toString());

  // Display the product information
  System.out.println(String.format("Product name: %s", product.getName()));
  System.out.println(
      String.format(
          "Product id: %s", product.getName().substring(product.getName().lastIndexOf('/') + 1)));
  System.out.println(String.format("Product display name: %s", product.getDisplayName()));
  System.out.println(String.format("Product description: %s", product.getDescription()));
  System.out.println(String.format("Product category: %s", product.getProductCategory()));
  System.out.println("Product labels:");
  System.out.println(
      String.format("Product labels: %s", product.getProductLabelsList().toString()));
}

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 Google Cloud Platform location.
const productPath = client.productPath(projectId, location, productId);

client
  .getProduct({name: productPath})
  .then(results => {
    const product = results[0];
    console.log(`Product name: ${product.name}`);
    console.log(`Product id: ${product.name.split('/').pop()}`);
    console.log(`Product display name: ${product.displayName}`);
    console.log(`Product description: ${product.description}`);
    console.log(`Product category: ${product.productCategory}`);
    console.log(`Product labels: ${product.productLabels}`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

Listing reference images

A product can have multiple associated reference images. The following example describes how to obtain all reference images linked to a single product.

Command-line

To list the reference images for a product, send GET 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 images.

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

If the response contains a nextPageToken, there are more results. You can repeat the request, adding a pageToken parameter with the value of nextPageToken:

GET https://vision.googleapis.com/v1p3beta1/projects/project-id/locations/location-id/products/product-id/referenceImages?pageToken=11

Python

from google.cloud import vision_v1p3beta1 as vision

def list_reference_images(
        project_id, location, product_id):
    """List all images in a product.
    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)

    # List all the reference images available in the product.
    reference_images = client.list_reference_images(parent=product_path)

    # Display the reference image information.
    for image in reference_images:
        print('Reference image name: {}'.format(image.name))
        print('Reference image id: {}'.format(image.name.split('/')[-1]))
        print('Reference image uri: {}'.format(image.uri))
        print('Reference image bounding polygons: {}'.format(
            image.bounding_polys))

Java

/**
 * List all images in a product.
 *
 * @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 listReferenceImagesOfProduct(
    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);

  for (ReferenceImage image : client.listReferenceImages(productPath.toString()).iterateAll()) {
    // Display the reference image information.
    System.out.println(String.format("Reference image name: %s", image.getName()));
    System.out.println(
        String.format(
            "Reference image id: %s",
            image.getName().substring(image.getName().lastIndexOf('/') + 1)));
    System.out.println(String.format("Reference image uri: %s", image.getUri()));
    System.out.println(
        String.format(
            "Reference image bounding polygons: %s \n", image.getBoundingPolysList().toString()));
  }
}

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 formattedParent = client.productPath(projectId, location, productId);
// const location = 'A compute region name';
// const productId = 'Id of the product';
const formattedParent = client.productPath(projectId, location, productId);
const request = {
  parent: formattedParent,
};

client
  .listReferenceImages(request)
  .then(responses => {
    const response = responses[0];
    response.forEach(image => {
      console.log(`image.name: ${image.name}`);
      console.log(`image.uri: ${image.uri}`);
    });
  })
  .catch(err => {
    console.log(err);
  });

Getting a single reference image

You can also get a single reference image linked to a product.

Command-line

To get information for a single image, send a GET 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 get.

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

Python

from google.cloud import vision_v1p3beta1 as vision

def get_reference_image(
        project_id, location, product_id, reference_image_id):
    """Get info about 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)

    # Get complete detail of the reference image.
    image = client.get_reference_image(name=reference_image_path)

    # Display the reference image information.
    print('Reference image name: {}'.format(image.name))
    print('Reference image id: {}'.format(image.name.split('/')[-1]))
    print('Reference image uri: {}'.format(image.uri))
    print('Reference image bounding polygons: {}'.format(image.bounding_polys))

Java

/**
 * Get info about 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 getReferenceImage(
    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);

  // Get complete detail of the reference image.
  ReferenceImage image = client.getReferenceImage(referenceImagePath);

  // Display the reference image information.
  System.out.println(String.format("Reference image name: %s", image.getName()));
  System.out.println(
      String.format(
          "Reference image id: %s",
          image.getName().substring(image.getName().lastIndexOf('/') + 1)));
  System.out.println(String.format("Reference image uri: %s", image.getUri()));
  System.out.println(
      String.format(
          "Reference image bounding polygons: %s \n", image.getBoundingPolysList().toString()));
}

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
  .getReferenceImage(request)
  .then(responses => {
    const response = responses[0];
    console.log(`response.name: ${response.name}`);
    console.log(`response.uri: ${response.uri}`);
  })
  .catch(err => {
    console.log(err);
  });

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

Send feedback about...

Cloud Vision API
Need help? Visit our support page.