storyblok / storyblok-nuxt

Storyblok Nuxt module
https://www.storyblok.com/tp/nuxt-js-multilanguage-website-tutorial
MIT License
276 stars 43 forks source link

how to create a story from nuxt to storyblok with $storyblok #4

Closed folamy closed 5 years ago

folamy commented 5 years ago

All want is to create story or edit a story content thanks

DominikAngerer commented 5 years ago

Creating a Story can only be done using the management API and our universal client; the $storyblok , $storyapi and $storybridge are only using the content delivery api by default. Make sure to never expose your management access token to the client as everybody would be able to perform all your CRUD operations: https://www.storyblok.com/docs/management-api/stories#creating-a-story-via-the-api

https://github.com/storyblok/storyblok-js-client#method-storyblokpost-only-management-api

// 1. Require the Storyblok client
const StoryblokClient = require('storyblok-js-client')
const spaceId = 12345

// 2. Initialize the client with the oauth token
// from the my account area at https://app.storyblok.com
let Storyblok = new StoryblokClient({
  oauthToken: 'YOUR_OAUTH_TOKEN'
})

Storyblok.post(`spaces/${spaceId}/stories`, {story: {name: 'xy', slug: 'xy'}})
Storyblok.put(`spaces/${spaceId}/stories/1`, {story: {name: 'xy', slug: 'xy'}})
Storyblok.delete(`spaces/${spaceId}/stories/1`, null)