After you have created a product set, you can create products and add them
to the product set. When you create a product, you must provide a display name
for the product and a product category. Currently supported categories are:
homegoods-v2
, apparel-v2
,
toys-v2
, packagedgoods-v1
,
and general-v1
*.
You can also supply an optional description of your product, and optional
labels for your product. Labels are key/value pairs that describe your product
such as color=black
or style=mens
. You can include labels to filter the
results of a product search to only search certain product images.
Creating a product
You can use online import to create an individual product. After a product is created you can then add a reference image to it or add it to one or more product sets.
Before using any of the request data, make the following replacements:
- PROJECT_ID: Your Google Cloud project ID.
- LOCATION_ID: A valid location identifier. Valid location identifiers are:
us-west1
,us-east1
,europe-west1
, andasia-east1
. - DISPLAY_NAME: A string display name of your choosing.
- PRODUCT_DESCRIPTION: A string description of your choosing.
- product-category: A valid product category. The
following product categories are currently available:
homegoods-v2
,apparel-v2
,toys-v2
,packagedgoods-v1
, andgeneral-v1
. productLabels
: One or more key-value pairs associated with a product. Each KEY_STRING must have an associated VALUE_STRING.
HTTP method and URL:
POST https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products
Request JSON body:
{ "displayName": "display-name ", "description": "product-description ", "productCategory": "product-category ", "productLabels": [ { "key": "key-string ", "value": "value-string " } ] }
To send your request, choose one of these options:
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:project-id " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products"
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products" | Select-Object -Expand Content
Example request body:
{ "displayName": "sample-product-1234", "description": "Athletic shorts", "productCategory": "apparel-v2", "productLabels": [ { "key": "style", "value": "womens" }, { "key": "color", "value": "blue" } ] }
If the request is successful, the server returns a 200 OK
HTTP status code and the
response in JSON format.
You should see output similar to the following. You can use the product ID
(37b9811d308c4e42
, in this case) to perform other operations on the product.
{ "name": "projects/project-id /locations/location-id /products/37b9811d308c4e42", "displayName": "sample-product-456", "description": "Athletic shorts", "productCategory": "apparel-v2", "productLabels": [ { "key": "style", "value": "womens" }, { "key": "color", "value": "blue" } ] }
Creating a product using a specified productId
When creating a product resource you have the option of providing a specific product ID with your request.
This information is passed as a query to the request URL
(?productId=product-id
).
Before using any of the request data, make the following replacements:
- PROJECT_ID: Your Google Cloud project ID.
- LOCATION_ID: A valid location identifier. Valid location identifiers are:
us-west1
,us-east1
,europe-west1
, andasia-east1
. - PRODUCT_ID: The ID for the product that is associated with a reference image. This ID is either randomly set or specified by the user at product creation time.
- DISPLAY_NAME: A string display name of your choosing.
- PRODUCT_DESCRIPTION: A string description of your choosing.
- product-category: A valid product category. The
following product categories are currently available:
homegoods-v2
,apparel-v2
,toys-v2
,packagedgoods-v1
, andgeneral-v1
. productLabels
: One or more key-value pairs associated with a product. Each KEY_STRING must have an associated VALUE_STRING.
HTTP method and URL:
POST https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products?productId=product-id
Request JSON body:
{ "displayName": "display-name ", "description": "product-description ", "productCategory": "product-category ", "productLabels": [ { "key": "key-string ", "value": "value-string " } ] }
To send your request, choose one of these options:
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:project-id " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products?productId=product-id "
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products?productId=product-id " | Select-Object -Expand Content
Example request URL and body:
https://vision.googleapis.com/v1/projects/project-id /locations/location-id /products?productId=product-id-456
{ "displayName": "sample-product-456", "description": "Athletic shorts", "productCategory": "apparel-v2", "productLabels": [ { "key": "style", "value": "womens" }, { "key": "color", "value": "blue" } ] }
If the request is successful, the server returns a 200 OK
HTTP status code and the
response in JSON format.
You should see output similar to the following. You can use the product ID you set
(product-id-456
, in this case) to perform other operations on the product.
{ "name": "projects/project-id /locations/location-id /products/product-id-456", "displayName": "sample-product-456", "description": "Athletic shorts", "productCategory": "apparel-v2", "productLabels": [ { "key": "style", "value": "womens" }, { "key": "color", "value": "blue" } ] }
Sending a request with a product ID that already exists produces the following error:
{ "error": { "code": 409, "message": "Product with ID 'product-id ' already exists.", "status": "ALREADY_EXISTS", "details": [ { "@type": "type.googleapis.com/google.rpc.DebugInfo", "detail": "[ORIGINAL ERROR] generic::already_exists: Product with ID 'product-id ' already exists. [google.rpc.error_details_ext] { message: \"Product with ID \\'product-id \\' already exists.\" }" } ] } }
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Go API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Java API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Node.js API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Python API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
C#: Please follow the C# setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for Ruby.
Adding a product to a product set
When you have a product and product set available you can then add the product to the product set.
Before using any of the request data, make the following replacements:
- PROJECT_ID: Your Google Cloud project ID.
- LOCATION_ID: A valid location identifier. Valid location identifiers are:
us-west1
,us-east1
,europe-west1
, andasia-east1
. - PRODUCT_SET_ID: The ID for the product set you want to run the operation on.
- PRODUCT_NAME: The full resource name of the product.
Format:
projects/PROJECT_ID/locations/LOCATION_ID/products/PRODUCT_ID
HTTP method and URL:
POST https://vision.googleapis.com/v1/projects/project-id /locations/location-id /productSets/product-set-id :addProduct
Request JSON body:
{ "product": "product-name " }
To send your request, choose one of these options:
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:project-id " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1/projects/project-id /locations/location-id /productSets/product-set-id :addProduct"
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id /locations/location-id /productSets/product-set-id :addProduct" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{}
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Go API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Java API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Node.js API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Python API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
C#: Please follow the C# setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for Ruby.
Removing a product from a product set
You can also remove an existing product from a product set.
Before using any of the request data, make the following replacements:
- PROJECT_ID: Your Google Cloud project ID.
- LOCATION_ID: A valid location identifier. Valid location identifiers are:
us-west1
,us-east1
,europe-west1
, andasia-east1
. - PRODUCT_SET_ID: The ID for the product set you want to run the operation on.
- PRODUCT_NAME: The full resource name of the product.
Format:
projects/PROJECT_ID/locations/LOCATION_ID/products/PRODUCT_ID
HTTP method and URL:
POST https://vision.googleapis.com/v1/projects/project-id /locations/location-id /productSets/product-set-id :removeProduct
Request JSON body:
{ "product": "product-name " }
To send your request, choose one of these options:
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:project-id " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1/projects/project-id /locations/location-id /productSets/product-set-id :removeProduct"
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id /locations/location-id /productSets/product-set-id :removeProduct" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{}
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Go API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Java API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Node.js API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To learn how to install and use the client library for Vision API Product Search, see Vision API Product Search client libraries. For more information, see the Vision API Product Search Python API reference documentation.
To authenticate to Vision API Product Search, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
C#: Please follow the C# setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Vision API Product Search reference documentation for Ruby.