Skip to content

Instantly share code, notes, and snippets.

@tonyspiro
Last active May 21, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyspiro/9edb8b87312de8395a9b9eb6a77c8bce to your computer and use it in GitHub Desktop.
Save tonyspiro/9edb8b87312de8395a9b9eb6a77c8bce to your computer and use it in GitHub Desktop.
Cosmic JS - Bucket Setup Example
const bucketSetupExample = async () => {
const Cosmic = require('cosmicjs')
const api = Cosmic({
token: '' /* Your secret authentication token found in Account Settings > Authentication */
})
try {
const response = await api.addBucket({
title: 'New Test Bucket',
slug: 'something-totally-unique'
})
const bucket = api.bucket({
slug: response.bucket.slug
})
// Add Pages Object Type
const objectType = await bucket.addObjectType({
title: 'Pages',
singular: 'Page',
slug: 'pages'
})
// Add Pages
const home = await bucket.addObject({
title: 'Home',
slug: 'home',
type_slug: 'pages',
content: 'This is the home page content area. <strong>HTML welcome</strong>!',
metafields: [{
type: 'text',
key: 'headline',
title: 'Headline',
value: 'This is the HOME PAGE!'
}]
})
console.log(home)
const about = await bucket.addObject({
title: 'About',
slug: 'about',
type_slug: 'pages',
content: 'This is the about page content area. <strong>HTML welcome</strong>!',
metafields: [{
type: 'text',
key: 'headline',
title: 'Headline',
value: 'This is the ABOUT PAGE!'
}]
})
console.log(about)
const contact = await bucket.addObject({
title: 'Contact',
slug: 'contact',
type_slug: 'pages',
content: 'This is the contact page content area. <strong>HTML welcome</strong>!',
metafields: [{
type: 'text',
key: 'headline',
title: 'Headline',
value: 'This is the CONTACT PAGE!'
}]
})
console.log(contact)
// Get all Bucket Data
const bucket_data = await bucket.getBucket()
console.log(bucket_data)
} catch(e) {
throw console.log(e)
}
}
bucketSetupExample()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment