A product set is a simple container for a group of products.
Creating an empty product set
It's best to use a single product set for all of your items, and create additional product sets for testing as you need. The following code samples show you how to create an empty product set.
REST
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.
HTTP method and URL:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets
Request JSON body:
{ "displayName": "display-name" }
To send your request, choose one of these options:
curl
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"
PowerShell
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" | Select-Object -Expand Content
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 set ID
(b6d809615b6dd675
, in this case) to perform other operations on the product set.
{ "name": "projects/project-id/locations/location-id/productSets/b6d809615b6dd675", "displayName": "new-product-set" }
Go
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.
Java
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.
Node.js
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.
Python
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.
Additional languages
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.
Using bulk import to create a product set with products
You can also use the bulk import function to simultaneously create a product set, create multiple products and their reference images.
Various references for the product set, products, and reference images are all set in the bulk import CSV you use. For more information, see Formatting a bulk import CSV.
Perform bulk import by running the following code:
REST
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
. - STORAGE_PATH: A Cloud Storage bucket/directory where your input CSV file is stored. The requesting user must have at least read permission to the bucket.
HTTP method and URL:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets:import
Request JSON body:
{ "inputConfig": { "gcsSource": { "csvFileUri": "storage-path" } } }
To send your request, choose one of these options:
curl
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:import"
PowerShell
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:import" | Select-Object -Expand Content
You should see output similar to the following. You can use the operation ID
(f10f34e32c40a710
, in this case) to get the status of the task. For an
example, see Getting an operation's status:
{ "name": "projects/project-id/locations/location-id/operations/f10f34e32c40a710" }
After the long-running operation completes you can get the details of the import operation. The response should look similar to the following:
{ "name": "locations/location-id/operations/f10f34e32c40a710", "metadata": { "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata", "state": "SUCCESSFUL", "submitTime": "2019-12-06T21:16:04.476466873Z", "endTime": "2019-12-06T21:16:40.594258084Z" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.vision.v1.ImportProductSetsResponse", "referenceImages": [ { "name": "projects/project-id/locations/location-id/products/product_id0/referenceImages/image0", "uri": "gs://my-storage-bucket/img_039.jpg" }, { "name": "projects/project-id/locations/location-id/products/product_id1/referenceImages/image1", "uri": "gs://my-storage-bucket/img_105.jpg" }, { "name": "projects/project-id/locations/location-id/products/product_id2/referenceImages/image2", "uri": "gs://my-storage-bucket/img_224.jpg" }, { "name": "projects/project-id/locations/location-id/products/product_id3/referenceImages/image3", "uri": "gs://my-storage-bucket/img_385.jpg" } ], "statuses": [ {}, {}, {}, {} ] } }
Go
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.
Java
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.
Node.js
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.
Python
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.
Additional languages
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.
Getting the status of an operation
Several operations you request are long-running, such as product set creation via bulk import, purging a product set, and purging orphaned products. These types of requests will return a JSON with an operation ID that you can use to get the status of the operation.
For example, a batch delete (purge
) request returns the following JSON:
{ "name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626" }
In this case, the operation ID is bc4e1d412863e626
. The following samples
show how to get the status of this operation with this ID.
REST
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
. - OPERATION_ID: The ID of your operation. The ID is the last element of the name
of your operation. For example:
- operation name:
projects/PROJECT_ID/locations/LOCATION_ID/operations/bc4e1d412863e626
- operation id:
bc4e1d412863e626
- operation name:
HTTP method and URL:
GET https://vision.googleapis.com/v1/locations/location-id/operations/operation-id
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-id" \
"https://vision.googleapis.com/v1/locations/location-id/operations/operation-id"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-id" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/locations/location-id/operations/operation-id" | Select-Object -Expand Content
{ "name": "locations/location-id/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata", "state": "SUCCESSFUL", "submitTime": "2019-09-04T15:58:39.131591882Z", "endTime": "2019-09-04T15:58:43.099020580Z" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest", "parent": "projects/project-id/locations/location-id", "productSetPurgeConfig": { "productSetId": "project-set-id" }, "force": true } }
You should see output similar to the following for a completed purge orphaned products operation:
{ "name": "locations/location-id/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata", "state": "SUCCESSFUL", "submitTime": "2019-09-04T16:08:38.278197397Z", "endTime": "2019-09-04T16:08:45.075778639Z" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest", "parent": "projects/project-id/locations/location-id", "deleteOrphanProducts": true, "force": true } }