ProductSearchClient

ProductSearchClient

Manages Products and ProductSets of reference images for use in product search. It uses the following resource model:

  • The API has a collection of ProductSet resources, named projects/* /locations/* /productSets/*, which acts as a way to put different products into groups to limit identification.

In parallel,

  • The API has a collection of Product resources, named projects/* /locations/* /products/*

  • Each Product has a collection of ReferenceImage resources, named projects/* /locations/* /products/* /referenceImages/*

Constructor

new ProductSearchClient(optionsopt)

Construct an instance of ProductSearchClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. See the subsequent parameters for more details.

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise function <optional>

Custom promise module to use instead of native Promises.

apiEndpoint string <optional>

The domain name of the API remote host.

Source:

Members

(static) apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

Source:

(static) port

The port for this API service.

Source:

(static) scopes

The scopes needed to make gRPC calls for every method defined in this service.

Source:

(static) servicePath

The DNS address for this API service.

Source:

Methods

addProductToProductSet(request, optionsopt, callbackopt) → {Promise}

Adds a Product to the specified ProductSet. If the Product is already present, no change is made.

One Product can be added to at most 100 ProductSets.

Possible errors:

  • Returns NOT_FOUND if the Product or the ProductSet doesn't exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The resource name for the ProductSet to modify.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

product string

The resource name for the Product to be added to this ProductSet.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');
const product = '';
const request = {
  name: formattedName,
  product: product,
};
client.addProductToProductSet(request).catch(err => {
  console.error(err);
});

createProduct(request, optionsopt, callbackopt) → {Promise}

Creates and returns a new product resource.

Possible errors:

  • Returns INVALID_ARGUMENT if display_name is missing or longer than 4096 characters.
  • Returns INVALID_ARGUMENT if description is longer than 4096 characters.
  • Returns INVALID_ARGUMENT if product_category is missing or invalid.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The project in which the Product should be created.

Format is projects/PROJECT_ID/locations/LOC_ID.

product Object

The product to create.

This object should have the same structure as Product

productId string

A user-supplied resource id for this Product. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Product.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
const product = {};
const productId = '';
const request = {
  parent: formattedParent,
  product: product,
  productId: productId,
};
client.createProduct(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

createProductSet(request, optionsopt, callbackopt) → {Promise}

Creates and returns a new ProductSet resource.

Possible errors:

  • Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The project in which the ProductSet should be created.

Format is projects/PROJECT_ID/locations/LOC_ID.

productSet Object

The ProductSet to create.

This object should have the same structure as ProductSet

productSetId string

A user-supplied resource id for this ProductSet. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ProductSet.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
const productSet = {};
const productSetId = '';
const request = {
  parent: formattedParent,
  productSet: productSet,
  productSetId: productSetId,
};
client.createProductSet(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

createReferenceImage(request, optionsopt, callbackopt) → {Promise}

Creates and returns a new ReferenceImage resource.

The bounding_poly field is optional. If bounding_poly is not specified, the system will try to detect regions of interest in the image that are compatible with the product_category on the parent product. If it is specified, detection is ALWAYS skipped. The system converts polygons into non-rotated rectangles.

Note that the pipeline will resize the image if the image resolution is too large to process (above 50MP).

Possible errors:

  • Returns INVALID_ARGUMENT if the image_uri is missing or longer than 4096 characters.
  • Returns INVALID_ARGUMENT if the product does not exist.
  • Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing compatible with the parent product's product_category is detected.
  • Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

Resource name of the product in which to create the reference image.

Format is projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID.

referenceImage Object

The reference image to create. If an image ID is specified, it is ignored.

This object should have the same structure as ReferenceImage

referenceImageId string

A user-supplied resource id for the ReferenceImage to be added. If set, the server will attempt to use this value as the resource id. If it is already in use, an error is returned with code ALREADY_EXISTS. Must be at most 128 characters long. It cannot contain the character /.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ReferenceImage.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.productPath('[PROJECT]', '[LOCATION]', '[PRODUCT]');
const referenceImage = {};
const referenceImageId = '';
const request = {
  parent: formattedParent,
  referenceImage: referenceImage,
  referenceImageId: referenceImageId,
};
client.createReferenceImage(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

deleteProduct(request, optionsopt, callbackopt) → {Promise}

Permanently deletes a product and its reference images.

Metadata of the product and all its images will be deleted right away, but search queries against ProductSets containing the product may still work until all related caches are refreshed.

Possible errors:

  • Returns NOT_FOUND if the product does not exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Resource name of product to delete.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productPath('[PROJECT]', '[LOCATION]', '[PRODUCT]');
client.deleteProduct({name: formattedName}).catch(err => {
  console.error(err);
});

deleteProductSet(request, optionsopt, callbackopt) → {Promise}

Permanently deletes a ProductSet. All Products and ReferenceImages in the ProductSet will be deleted.

The actual image files are not deleted from Google Cloud Storage.

Possible errors:

  • Returns NOT_FOUND if the ProductSet does not exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Resource name of the ProductSet to delete.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');
client.deleteProductSet({name: formattedName}).catch(err => {
  console.error(err);
});

deleteReferenceImage(request, optionsopt, callbackopt) → {Promise}

Permanently deletes a reference image.

The image metadata will be deleted right away, but search queries against ProductSets containing the image may still work until all related caches are refreshed.

The actual image files are not deleted from Google Cloud Storage.

Possible errors:

  • Returns NOT_FOUND if the reference image does not exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The resource name of the reference image to delete.

Format is:

projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.referenceImagePath('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]');
client.deleteReferenceImage({name: formattedName}).catch(err => {
  console.error(err);
});

getProduct(request, optionsopt, callbackopt) → {Promise}

Gets information associated with a Product.

Possible errors:

  • Returns NOT_FOUND if the Product does not exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Resource name of the Product to get.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Product.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productPath('[PROJECT]', '[LOCATION]', '[PRODUCT]');
client.getProduct({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProductSet(request, optionsopt, callbackopt) → {Promise}

Gets information associated with a ProductSet.

Possible errors:

  • Returns NOT_FOUND if the ProductSet does not exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Resource name of the ProductSet to get.

Format is: projects/PROJECT_ID/locations/LOG_ID/productSets/PRODUCT_SET_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ProductSet.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');
client.getProductSet({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId(callback)

Return the project ID used by this class.

Parameters:
Name Type Description
callback function

the callback to be called with the current project Id.

Source:

getReferenceImage(request, optionsopt, callbackopt) → {Promise}

Gets information associated with a ReferenceImage.

Possible errors:

  • Returns NOT_FOUND if the specified image does not exist.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The resource name of the ReferenceImage to get.

Format is:

projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID/referenceImages/IMAGE_ID.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ReferenceImage.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.referenceImagePath('[PROJECT]', '[LOCATION]', '[PRODUCT]', '[REFERENCE_IMAGE]');
client.getReferenceImage({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

importProductSets(request, optionsopt, callbackopt) → {Promise}

Asynchronous API that imports a list of reference images to specified product sets based on a list of image information.

The google.longrunning.Operation API can be used to keep track of the progress and results of the request. Operation.metadata contains BatchOperationMetadata. (progress) Operation.response contains ImportProductSetsResponse. (results)

The input source of this method is a csv file on Google Cloud Storage. For the format of the csv file please see ImportProductSetsGcsSource.csv_file_uri.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
parent string

The project in which the ProductSets should be imported.

Format is projects/PROJECT_ID/locations/LOC_ID.

inputConfig Object

The input content for the list of requests.

This object should have the same structure as ImportProductSetsInputConfig

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is a gax.Operation object.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
const inputConfig = {};
const request = {
  parent: formattedParent,
  inputConfig: inputConfig,
};

// Handle the operation using the promise pattern.
client.importProductSets(request)
  .then(responses => {
    const [operation, initialApiResponse] = responses;

    // Operation#promise starts polling for the completion of the LRO.
    return operation.promise();
  })
  .then(responses => {
    const result = responses[0];
    const metadata = responses[1];
    const finalApiResponse = responses[2];
  })
  .catch(err => {
    console.error(err);
  });

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
const inputConfig = {};
const request = {
  parent: formattedParent,
  inputConfig: inputConfig,
};

// Handle the operation using the event emitter pattern.
client.importProductSets(request)
  .then(responses => {
    const [operation, initialApiResponse] = responses;

    // Adding a listener for the "complete" event starts polling for the
    // completion of the operation.
    operation.on('complete', (result, metadata, finalApiResponse) => {
      // doSomethingWith(result);
    });

    // Adding a listener for the "progress" event causes the callback to be
    // called on any change in metadata when the operation is polled.
    operation.on('progress', (metadata, apiResponse) => {
      // doSomethingWith(metadata)
    });

    // Adding a listener for the "error" event handles any errors found during polling.
    operation.on('error', err => {
      // throw(err);
    });
  })
  .catch(err => {
    console.error(err);
  });

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
const inputConfig = {};
const request = {
  parent: formattedParent,
  inputConfig: inputConfig,
};

// Handle the operation using the await pattern.
const [operation] = await client.importProductSets(request);

const [response] = await operation.promise();

listProducts(request, optionsopt, callbackopt) → {Promise}

Lists products in an unspecified order.

Possible errors:

  • Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
parent string

The project OR ProductSet from which Products should be listed.

Format: projects/PROJECT_ID/locations/LOC_ID

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of Product.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListProductsResponse.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');

client.listProducts({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listProducts(nextRequest, options).then(callback);
  }
}
client.listProducts({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listProductSets(request, optionsopt, callbackopt) → {Promise}

Lists ProductSets in an unspecified order.

Possible errors:

  • Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
parent string

The project from which ProductSets should be listed.

Format is projects/PROJECT_ID/locations/LOC_ID.

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of ProductSet.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListProductSetsResponse.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');

client.listProductSets({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listProductSets(nextRequest, options).then(callback);
  }
}
client.listProductSets({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listProductSetsStream(request, optionsopt) → {Stream}

Equivalent to listProductSets, but returns a NodeJS Stream object.

This fetches the paged responses for listProductSets continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
parent string

The project from which ProductSets should be listed.

Format is projects/PROJECT_ID/locations/LOC_ID.

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
client.listProductSetsStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listProductsInProductSet(request, optionsopt, callbackopt) → {Promise}

Lists the Products in a ProductSet, in an unspecified order. If the ProductSet does not exist, the products field of the response will be empty.

Possible errors:

  • Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The ProductSet resource for which to retrieve Products.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of Product.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListProductsInProductSetResponse.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');

client.listProductsInProductSet({name: formattedName})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listProductsInProductSet(nextRequest, options).then(callback);
  }
}
client.listProductsInProductSet({name: formattedName}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listProductsInProductSetStream(request, optionsopt) → {Stream}

Equivalent to listProductsInProductSet, but returns a NodeJS Stream object.

This fetches the paged responses for listProductsInProductSet continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
name string

The ProductSet resource for which to retrieve Products.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');
client.listProductsInProductSetStream({name: formattedName})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listProductsStream(request, optionsopt) → {Stream}

Equivalent to listProducts, but returns a NodeJS Stream object.

This fetches the paged responses for listProducts continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
parent string

The project OR ProductSet from which Products should be listed.

Format: projects/PROJECT_ID/locations/LOC_ID

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
client.listProductsStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listReferenceImages(request, optionsopt, callbackopt) → {Promise}

Lists reference images.

Possible errors:

  • Returns NOT_FOUND if the parent product does not exist.
  • Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
parent string

Resource name of the product containing the reference images.

Format is projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID.

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is Array of ReferenceImage.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListReferenceImagesResponse.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.productPath('[PROJECT]', '[LOCATION]', '[PRODUCT]');

client.listReferenceImages({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.productPath('[PROJECT]', '[LOCATION]', '[PRODUCT]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listReferenceImages(nextRequest, options).then(callback);
  }
}
client.listReferenceImages({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listReferenceImagesStream(request, optionsopt) → {Stream}

Equivalent to listReferenceImages, but returns a NodeJS Stream object.

This fetches the paged responses for listReferenceImages continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Attributes Description
parent string

Resource name of the product containing the reference images.

Format is projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID.

pageSize number <optional>

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Source:
See:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedParent = client.productPath('[PROJECT]', '[LOCATION]', '[PRODUCT]');
client.listReferenceImagesStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

locationPath(project, location) → {String}

Return a fully-qualified location resource name string.

Parameters:
Name Type Description
project String
location String
Source:

matchLocationFromLocationName(locationName) → {String}

Parse the locationName from a location resource.

Parameters:
Name Type Description
locationName String

A fully-qualified path representing a location resources.

Source:

matchLocationFromProductName(productName) → {String}

Parse the productName from a product resource.

Parameters:
Name Type Description
productName String

A fully-qualified path representing a product resources.

Source:

matchLocationFromProductSetName(productSetName) → {String}

Parse the productSetName from a product_set resource.

Parameters:
Name Type Description
productSetName String

A fully-qualified path representing a product_set resources.

Source:

matchLocationFromReferenceImageName(referenceImageName) → {String}

Parse the referenceImageName from a reference_image resource.

Parameters:
Name Type Description
referenceImageName String

A fully-qualified path representing a reference_image resources.

Source:

matchProductFromProductName(productName) → {String}

Parse the productName from a product resource.

Parameters:
Name Type Description
productName String

A fully-qualified path representing a product resources.

Source:

matchProductFromReferenceImageName(referenceImageName) → {String}

Parse the referenceImageName from a reference_image resource.

Parameters:
Name Type Description
referenceImageName String

A fully-qualified path representing a reference_image resources.

Source:

matchProductSetFromProductSetName(productSetName) → {String}

Parse the productSetName from a product_set resource.

Parameters:
Name Type Description
productSetName String

A fully-qualified path representing a product_set resources.

Source:

matchProjectFromLocationName(locationName) → {String}

Parse the locationName from a location resource.

Parameters:
Name Type Description
locationName String

A fully-qualified path representing a location resources.

Source:

matchProjectFromProductName(productName) → {String}

Parse the productName from a product resource.

Parameters:
Name Type Description
productName String

A fully-qualified path representing a product resources.

Source:

matchProjectFromProductSetName(productSetName) → {String}

Parse the productSetName from a product_set resource.

Parameters:
Name Type Description
productSetName String

A fully-qualified path representing a product_set resources.

Source:

matchProjectFromReferenceImageName(referenceImageName) → {String}

Parse the referenceImageName from a reference_image resource.

Parameters:
Name Type Description
referenceImageName String

A fully-qualified path representing a reference_image resources.

Source:

matchReferenceImageFromReferenceImageName(referenceImageName) → {String}

Parse the referenceImageName from a reference_image resource.

Parameters:
Name Type Description
referenceImageName String

A fully-qualified path representing a reference_image resources.

Source:

productPath(project, location, product) → {String}

Return a fully-qualified product resource name string.

Parameters:
Name Type Description
project String
location String
product String
Source:

productSetPath(project, location, productSet) → {String}

Return a fully-qualified product_set resource name string.

Parameters:
Name Type Description
project String
location String
productSet String
Source:

referenceImagePath(project, location, product, referenceImage) → {String}

Return a fully-qualified reference_image resource name string.

Parameters:
Name Type Description
project String
location String
product String
referenceImage String
Source:

removeProductFromProductSet(request, optionsopt, callbackopt) → {Promise}

Removes a Product from the specified ProductSet.

Possible errors:

  • Returns NOT_FOUND If the Product is not found under the ProductSet.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

The resource name for the ProductSet to modify.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

product string

The resource name for the Product to be removed from this ProductSet.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const formattedName = client.productSetPath('[PROJECT]', '[LOCATION]', '[PRODUCT_SET]');
const product = '';
const request = {
  name: formattedName,
  product: product,
};
client.removeProductFromProductSet(request).catch(err => {
  console.error(err);
});

updateProduct(request, optionsopt, callbackopt) → {Promise}

Makes changes to a Product resource. Only display_name, description and labels can be updated right now.

If labels are updated, the change will not be reflected in queries until the next index time.

Possible errors:

  • Returns NOT_FOUND if the Product does not exist.
  • Returns INVALID_ARGUMENT if display_name is present in update_mask but is missing from the request or longer than 4096 characters.
  • Returns INVALID_ARGUMENT if description is present in update_mask but is longer than 4096 characters.
  • Returns INVALID_ARGUMENT if product_category is present in update_mask.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
product Object

The Product resource which replaces the one on the server. product.name is immutable.

This object should have the same structure as Product

updateMask Object

The FieldMask that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask paths include product_labels, display_name and description.

This object should have the same structure as FieldMask

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Product.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const product = {};
const updateMask = {};
const request = {
  product: product,
  updateMask: updateMask,
};
client.updateProduct(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

updateProductSet(request, optionsopt, callbackopt) → {Promise}

Makes changes to a ProductSet resource. Only display_name can be updated currently.

Possible errors:

  • Returns NOT_FOUND if the ProductSet does not exist.
  • Returns INVALID_ARGUMENT if display_name is present in update_mask but missing from the request or longer than 4096 characters.
Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
productSet Object

The ProductSet resource which replaces the one on the server.

This object should have the same structure as ProductSet

updateMask Object

The FieldMask that specifies which fields to update. If update_mask isn't specified, all mutable fields are to be updated. Valid mask path is display_name.

This object should have the same structure as FieldMask

options Object <optional>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback function <optional>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ProductSet.

Source:
Example
const vision = require('@google-cloud/vision');

const client = new vision.v1p3beta1.ProductSearchClient({
  // optional auth parameters.
});

const productSet = {};
const updateMask = {};
const request = {
  productSet: productSet,
  updateMask: updateMask,
};
client.updateProductSet(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });