Last active
June 7, 2022 06:32
-
-
Save tonyspiro/5de0961d810a82cf9282482854ac5395 to your computer and use it in GitHub Desktop.
Get Objects from Cosmic by type
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: '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