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.
REST & CMD LINE
Before using any of the request data below, make the following replacements:
- project-id: Your GCP 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:
curl
Save the request body in a file called request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products
PowerShell
Save the request body in a file called request.json
,
and execute the following command:
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
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" } ] }
C#
Go
Java
Node.js
PHP
Python
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.
REST & CMD LINE
Before using any of the request data below, make the following replacements:
- project-id: Your GCP 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:
curl
Save the request body in a file called request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-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
PowerShell
Save the request body in a file called request.json
,
and execute the following command:
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
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:
{}
C#
Go
Java
Node.js
PHP
Python
Ruby
Removing a product from a product set
You can also remove an existing product from a product set.
REST & CMD LINE
Before using any of the request data below, make the following replacements:
- project-id: Your GCP 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:
curl
Save the request body in a file called request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-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
PowerShell
Save the request body in a file called request.json
,
and execute the following command:
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
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:
{}
C#
Go
Java
Node.js
PHP
Python
Ruby