Skip to content

Instantly share code, notes, and snippets.

@tonyspiro
Last active June 7, 2022 06:30
Show Gist options
  • Save tonyspiro/b3c236fac796cb46779e72cd0f741939 to your computer and use it in GitHub Desktop.
Save tonyspiro/b3c236fac796cb46779e72cd0f741939 to your computer and use it in GitHub Desktop.
Get Objects from Cosmic by metadata value
// index.js
const api = require('cosmicjs')() // empty init
const bucket = api.bucket({
slug: 'docs-ecommerce-app-production', // YOUR_BUCKET_SLUG
read_key: '49TG2OEZMVML9fNvVObbFOEsjkFaCYpbVIP1kb8kYCY6RMWqBf' // YOUR_BUCKET_READ_KEY
})
const app = async () => {
const data = await bucket.getObjects({
query: {
type: 'products',
'metadata.category':'Electronics'
},
props: 'slug,title,metadata.category' // declare your response properties
})
const products = data.objects
console.log(JSON.stringify(products, null, 2))
}
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment