Create a product set

Stay organized with collections Save and categorize content based on your preferences.

Create a product set.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


import (

	vision ""
	visionpb ""

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

	req := &visionpb.CreateProductSetRequest{
		Parent:       fmt.Sprintf("projects/%s/locations/%s", projectID, location),
		ProductSetId: productSetID,
		ProductSet: &visionpb.ProductSet{
			DisplayName: productSetDisplayName,

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

	fmt.Fprintf(w, "Product set name: %s\n", resp.Name)

	return nil


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

    // A resource that represents Google Cloud Platform location.
    String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);

    // Create a product set with the product set specification in the region.
    ProductSet myProductSet =
    CreateProductSetRequest request =
    ProductSet productSet = client.createProductSet(request);
    // Display the product set information
    System.out.println(String.format("Product set name: %s", productSet.getName()));


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

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

async function createProductSet() {
   * 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';
  // const productSetDisplayName = 'Display name of the product set';

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

  const productSet = {
    displayName: productSetDisplayName,

  const request = {
    parent: locationPath,
    productSet: productSet,
    productSetId: productSetId,

  const [createdProductSet] = await client.createProductSet(request);
  console.log(`Product Set name: ${}`);


from import vision

def create_product_set(
        project_id, location, product_set_id, product_set_display_name):
    """Create a product set.
        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 = f"projects/{project_id}/locations/{location}"

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

    # The response is the product set with `name` populated.
    response = client.create_product_set(

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

What's next

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