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

Function main

vision/productSearch/createProduct.js:17–59  ·  view source on GitHub ↗
(
  projectId,
  location,
  productId,
  productDisplayName,
  productCategory
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17function main(
18 projectId,
19 location,
20 productId,
21 productDisplayName,
22 productCategory
23) {
24 // [START vision_product_search_create_product]
25 // Imports the Google Cloud client library
26 const vision = require('@google-cloud/vision');
27
28 // Creates a client
29 const client = new vision.ProductSearchClient();
30 async function createProduct() {
31 /**
32 * TODO(developer): Uncomment the following line before running the sample.
33 */
34 // const projectId = 'Your Google Cloud project Id';
35 // const location = 'A compute region name';
36 // const productId = 'Id of the product';
37 // const productDisplayName = 'Display name of the product';
38 // const productCategory = 'Catoegory of the product';
39
40 // Resource path that represents Google Cloud Platform location.
41 const locationPath = client.locationPath(projectId, location);
42
43 const product = {
44 displayName: productDisplayName,
45 productCategory: productCategory,
46 };
47
48 const request = {
49 parent: locationPath,
50 product: product,
51 productId: productId,
52 };
53
54 const [createdProduct] = await client.createProduct(request);
55 console.log(`Product name: ${createdProduct.name}`);
56 }
57 createProduct();
58 // [END vision_product_search_create_product]
59}
60process.on('unhandledRejection', err => {
61 console.error(err.message);
62 process.exitCode = 1;

Callers 1

createProduct.jsFile · 0.70

Calls 1

createProductFunction · 0.70

Tested by

no test coverage detected