Skip to content

Instantly share code, notes, and snippets.

@tonyspiro
Last active June 7, 2022 06:32
Show Gist options
  • Save tonyspiro/5de0961d810a82cf9282482854ac5395 to your computer and use it in GitHub Desktop.
Save tonyspiro/5de0961d810a82cf9282482854ac5395 to your computer and use it in GitHub Desktop.
Get Objects from Cosmic by type
// index.js
const api = require('cosmicjs')() // empty init
const bucket = api.bucket({
slug: 'simple-react-blog', // YOUR_BUCKET_SLUG
read_key: 'bucket-read-key' // YOUR_BUCKET_READ_KEY
})
const app = async () => {
const data = await bucket.getObjects({
query: {
type: 'posts'
},
props: 'slug,title,metadata.hero.imgix_url,metadata.author.title' // declare your response properties
})
const posts = data.objects
console.log(JSON.stringify(posts, null, 2))
}
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment