MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

vision/productSearch/updateProductLabels.js:17–68  ·  view source on GitHub ↗
(projectId, location, productId, key, value)

Source from the content-addressed store, hash-verified

15'use strict';
16
17function main(projectId, location, productId, key, value) {
18 // [START vision_product_search_update_product_labels]
19 // Imports the Google Cloud client library
20 const vision = require('@google-cloud/vision');
21
22 // Creates a client
23 const client = new vision.ProductSearchClient();
24
25 async function updateProductLabels() {
26 /**
27 * TODO(developer): Uncomment the following line before running the sample.
28 */
29 // const projectId = 'Your Google Cloud project Id';
30 // const location = 'A compute region name';
31 // const productId = 'Id of the product';
32 // const key = 'The key of the label';
33 // const value = 'The value of the label';
34
35 // Resource path that represents full path to the product.
36 const productPath = client.productPath(projectId, location, productId);
37
38 const product = {
39 name: productPath,
40 productLabels: [
41 {
42 key: key,
43 value: value,
44 },
45 ],
46 };
47
48 const updateMask = {
49 paths: ['product_labels'],
50 };
51
52 const request = {
53 product: product,
54 updateMask: updateMask,
55 };
56
57 const [updatedProduct] = await client.updateProduct(request);
58 console.log(`Product name: ${updatedProduct.name}`);
59 console.log(`Product display name: ${updatedProduct.displayName}`);
60 console.log(`Product description: ${updatedProduct.description}`);
61 console.log(`Product category: ${updatedProduct.productCategory}`);
62 console.log(
63 `Product Labels: ${updatedProduct.productLabels[0].key}: ${updatedProduct.productLabels[0].value}`
64 );
65 }
66 updateProductLabels();
67 // [END vision_product_search_update_product_labels]
68}
69
70process.on('unhandledRejection', err => {
71 console.error(err.message);

Callers 1

Calls 1

updateProductLabelsFunction · 0.85

Tested by

no test coverage detected