Last active
June 7, 2022 06:30
-
-
Save tonyspiro/b3c236fac796cb46779e72cd0f741939 to your computer and use it in GitHub Desktop.
Get Objects from Cosmic by metadata value
This file contains 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.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