Updating a product
You can update a product's labels via key-value pairs, such as "style=womens"
or "onSale=true"
, using the following code.
Command-line
When you send a PATCH
request all previous fields and their values will be erased
except for the productCategory
field, which is immutable.
Send all fields you need with values when making the PATCH
update request.
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. This can be the same as the previous display name or an updated value.
- description: A string description of your choosing. This can be the same as the
previous display name or an updated value. Omit the
description
field and value if you don't need it. productLabels
: One or more key-value pairs associated with a product. Each KEY_STRING must have an associated VALUE_STRING.
HTTP method and URL:
PATCH https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id
Request JSON body:
{ "displayName": "display-name", "description": "description", "productLabels": [ { "key": "key-string", "value": "value-string" }, { "key": "key-string", "value": "value-string" } ] }
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 PATCH \
-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/product-id"
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 PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products/product-id" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/project-id/locations/location-id/products/product-id", "displayName": "display-name", "description": "description", "productCategory": "apparel-v2", "productLabels": [ { "key": "style", "value": "womens" }, { "key": "onSale", "value": "true" } ] }
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.