Creating a product set resource

A product set is a simple container for a group of products.

We recommend a single product set for all of your items. You can create additional product sets for testing.

Command-line

To create a product set, send a POST to the https://vision.googleapis.com/v1p3beta1/{parent=projects/*/locations/*}/productSets endpoint in the following format.

  • 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 display-name with the display name for your new product set.

POST https://vision.googleapis.com/v1p3beta1/projects/project-id/locations/location-id/productSets
{
   'displayName' : 'display-name'
}

Python

For more on installing and creating a Vision Product Search client, refer to Vision Product Search Client Libraries.

from google.cloud import vision_v1p3beta1 as vision

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

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

    # Create a product set with the product set specification in the region.
    product_set = vision.types.ProductSet(
            display_name=product_set_display_name)

    # The response is the product set with `name` populated.
    response = client.create_product_set(
        parent=location_path,
        product_set=product_set,
        product_set_id=product_set_id)

    # Display the product set information.
    print('Product set name: {}'.format(response.name))

Java

For more on installing and creating a Vision Product Search client, refer to Vision Product Search Client Libraries.

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

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

  // Create a product set with the product set specification in the region.
  ProductSet myProductSet = ProductSet.newBuilder().setDisplayName(productSetDisplayName).build();
  CreateProductSetRequest request =
      CreateProductSetRequest.newBuilder()
          .setParent(projectLocation.toString())
          .setProductSet(myProductSet)
          .setProductSetId(productSetId)
          .build();
  ProductSet productSet = client.createProductSet(request);

  // Display the product set information
  System.out.println(String.format("Product set name: %s", productSet.getName()));
}

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

Send feedback about...

Cloud Vision API