Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Add Comment
Please, Sign In to add comment