Access Tokens
Storyblok offers a rich set of APIs and services for delivering and managing assets and content. Tokens protect access to these services.
Types
Storyblok broadly offers two types of tokens: management and content delivery.
Management tokens provide read and write access to a Storyblok account and its spaces. Use these tokens to perform CRUD operations via the Management API. Both the Personal Access Token and OAuth 2.0 Token are management tokens.
Content delivery tokens allow you to read the content and assets in one specific space. Use these tokens to integrate your frontend with the Content Delivery API. The Space Access Tokens, with various access types (public, private, asset, etc.), are content delivery tokens.
Personal access token
Use a personal access token to access the Management API. This token is account-specific and can be generated in the account settings. While generating it, you must set an expiration date. Additionally, you can give the token a name for easy identification.
Following is an example using the storyblok-js-client to send requests to the Management API with a personal access token.
// 1. Import the Storyblok client
import StoryblokClient from "storyblok-js-client";
const spaceId = "<YOUR_SPACE_ID>";
// 2. Initialize the client with the personal access token
const Storyblok = new StoryblokClient({
oauthToken: "<YOUR_PERSONAL_ACCESS_TOKEN>",
});
// Send requests
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);
Space access token
Use a space access token to read the content and assets stored in a Storyblok space. Generate this token within a space's settings. While generating this token, choose from a list of access levels. These levels control what the token will have access to.
- Public: Access
published
content. - Preview: Access
draft
as well aspublished
content. - Asset: Access private assets. Read more about private assets and how to use them in your application in this article.
- Theme: Access a theme for use by the Storyblok rendering service. The Storyblok rendering service is now deprecated.
Below is an example using the @storyblok/js package to fetch content from the Content Delivery API
import { storyblokInit, apiPlugin } from "@storyblok/js";
/* Use a Space Access token with access level of
Public or Preview */
const { storyblokApi } = storyblokInit({
accessToken: "YOUR_ACCESS_TOKEN",
use: [apiPlugin],
});
const { data } = await storyblokApi.get("cdn/stories", { version: "draft" });