Last active
June 7, 2022 06:30
-
-
Save tonyspiro/3ecf80f412201ec2931b226d3365a220 to your computer and use it in GitHub Desktop.
Get Objects from Cosmic by number metadata (less than or equal to)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.price': { | |
$lte: 10.00 | |
} | |
}, | |
props: 'slug,title,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