创建商品集后,您可以创建商品并将它们添加到商品集。创建商品时,您必须提供相应商品的显示名和商品类别。目前支持的类别包括 homegoods-v2
、apparel-v2
、toys-v2
、packagedgoods-v1
和 general-v1
*。
您还可以根据需要提供商品说明和商品标签。标签是描述您的商品的键值对,如 color=black
或 style=mens
。您可以添加标签,以过滤商品搜索结果,从而仅搜索特定商品图片。
创建商品
您可以使用在线导入功能来创建单件商品。创建商品后,您可以向其添加参考图片或将其添加到一个或多个商品集中。
REST 和命令行
在使用下面的任何请求数据之前,请先进行以下替换:
- project-id:您的 GCP 项目 ID。
- location-id:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - display-name:您选择的字符串显示名。
- product-description:您选择的字符串说明。
- product-category:有效的商品类别。目前提供了以下商品类别:
homegoods-v2
、apparel-v2
、toys-v2
、packagedgoods-v1
和general-v1
。 productLabels
:与商品关联的一个或多个键值对。每个 key-string 必须具有一个关联的 value-string。
HTTP 方法和网址:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/products
请求 JSON 正文:
{ "displayName": "display-name", "description": "product-description", "productCategory": "product-category", "productLabels": [ { "key": "key-string", "value": "value-string" } ] }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
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
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$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
请求正文示例:
{ "displayName": "sample-product-1234", "description": "Athletic shorts", "productCategory": "apparel-v2", "productLabels": [ { "key": "style", "value": "womens" }, { "key": "color", "value": "blue" } ] }
如果请求成功,服务器将返回一个 200 OK
HTTP 状态代码以及 JSON 格式的响应。
您应该会看到类似如下所示的输出。可以使用商品 ID(本例中为 37b9811d308c4e42
)对商品执行其他操作。
{ "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" } ] }
Go
Java
Node.js
Python
将商品添加到商品集
如果您有可用的商品和商品集,则可以将商品添加到商品集中。
REST 和命令行
在使用下面的任何请求数据之前,请先进行以下替换:
- project-id:您的 GCP 项目 ID。
- location-id:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - product-set-id:您要对其执行操作的商品集的 ID。
- product-name:商品的完整资源名称。
格式如下:
projects/project-id/locations/location-id/products/product-id
HTTP 方法和网址:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets/product-set-id:addProduct
请求 JSON 正文:
{ "product": "product-name" }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
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
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$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
您应该收到类似以下内容的 JSON 响应:
{}
Go
Java
Node.js
Python
从商品集移除商品
您还可以移除商品集中的现有商品。
REST 和命令行
在使用下面的任何请求数据之前,请先进行以下替换:
- project-id:您的 GCP 项目 ID。
- location-id:有效的位置标识符。有效的位置标识符包括
us-west1
、us-east1
、europe-west1
和asia-east1
。 - product-set-id:您要对其执行操作的商品集的 ID。
- product-name:商品的完整资源名称。
格式如下:
projects/project-id/locations/location-id/products/product-id
HTTP 方法和网址:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets/product-set-id:removeProduct
请求 JSON 正文:
{ "product": "product-name" }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
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
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$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
您应该收到类似以下内容的 JSON 响应:
{}
Go
Java
Node.js
Python