Last active
May 21, 2018 16:16
-
-
Save tonyspiro/9edb8b87312de8395a9b9eb6a77c8bce to your computer and use it in GitHub Desktop.
Cosmic JS - Bucket Setup Example
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
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