Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Objects from Cosmic by slug
// 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_READ_KEY
})
const app = async () => {
const data = await bucket.getObjects({
query: {
slug: 'a-wonderful-blog-post-about-earth'
},
props: 'slug,title,metadata.hero.imgix_url,metadata.author.title' // declare your response properties
})
const post = data.objects[0]
console.log(JSON.stringify(post, null, 2))
}
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment