Skip to content

Instantly share code, notes, and snippets.

@crysxd
Last active May 16, 2019 16:48
Show Gist options
  • Save crysxd/17621076d3a527af655cb7df7dfbb216 to your computer and use it in GitHub Desktop.
Save crysxd/17621076d3a527af655cb7df7dfbb216 to your computer and use it in GitHub Desktop.
List all product sets in Google Cloud Vision Product Search
list('your-project-id', 'your-location')
async function list(projectId, location) {
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);
const [productSets] = await client.listProductSets({parent: locationPath});
productSets.forEach(productSet => {
console.log(`Product Set name: ${productSet.name}`);
console.log(`Product Set display name: ${productSet.displayName}`);
console.log(`Product Set display name: ${new Date(productSet.indexTime.seconds * 1000)}`);
console.log(`Product Set index time: ${new Date(productSet.indexTime.seconds * 1000)}`);
});
console.warn('\n\nProduct sets with index time 0 are not ready!')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment