Guest User

Untitled

a guest
May 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. const bucketSetupExample = async () => {
  2. const Cosmic = require('cosmicjs')
  3. const api = Cosmic({
  4. token: '' /* Your secret authentication token found in Account Settings > Authentication */
  5. })
  6. try {
  7. const response = await api.addBucket({
  8. title: 'New Test Bucket',
  9. slug: 'something-totally-unique'
  10. })
  11. const bucket = api.bucket({
  12. slug: response.bucket.slug
  13. })
  14.  
  15. // Add Pages Object Type
  16. const objectType = await bucket.addObjectType({
  17. title: 'Pages',
  18. singular: 'Page',
  19. slug: 'pages'
  20. })
  21.  
  22. // Add Pages
  23. const home = await bucket.addObject({
  24. title: 'Home',
  25. slug: 'home',
  26. type_slug: 'pages',
  27. content: 'This is the home page content area. <strong>HTML welcome</strong>!',
  28. metafields: [{
  29. type: 'text',
  30. key: 'headline',
  31. title: 'Headline',
  32. value: 'This is the HOME PAGE!'
  33. }]
  34. })
  35. console.log(home)
  36.  
  37. const about = await bucket.addObject({
  38. title: 'About',
  39. slug: 'about',
  40. type_slug: 'pages',
  41. content: 'This is the about page content area. <strong>HTML welcome</strong>!',
  42. metafields: [{
  43. type: 'text',
  44. key: 'headline',
  45. title: 'Headline',
  46. value: 'This is the ABOUT PAGE!'
  47. }]
  48. })
  49. console.log(about)
  50.  
  51. const contact = await bucket.addObject({
  52. title: 'Contact',
  53. slug: 'contact',
  54. type_slug: 'pages',
  55. content: 'This is the contact page content area. <strong>HTML welcome</strong>!',
  56. metafields: [{
  57. type: 'text',
  58. key: 'headline',
  59. title: 'Headline',
  60. value: 'This is the CONTACT PAGE!'
  61. }]
  62. })
  63. console.log(contact)
  64.  
  65. // Get all Bucket Data
  66. const bucket_data = await bucket.getBucket()
  67. console.log(bucket_data)
  68.  
  69. } catch(e) {
  70. throw console.log(e)
  71. }
  72. }
  73. bucketSetupExample()
Add Comment
Please, Sign In to add comment