Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Objects from Cosmic by metadata value (not equal to)
// 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": {
$ne: "Food"
}
},
limit: 3,
props: 'slug,title,metadata.category,metadata.price' // 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