Created
August 13, 2021 10:47
-
-
Save DominikAngerer/3804c499aa9950a98d796b6090114f46 to your computer and use it in GitHub Desktop.
Export Storyblok Component Names
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
// Install dependency: npm install storyblok-js-client | |
const StoryblokClient = require('storyblok-js-client') | |
// This token allows CRUD operations to all your spaces and can be found in the | |
// "my account" section of our app: https://app.storyblok.com/#!/me/account | |
// DO NOT COMMIT THAT OAUTHTOKEN!! | |
const oauthToken = 'your_oauth_token' | |
// Initialize the client with the oauth token | |
const Storyblok = new StoryblokClient({ | |
oauthToken: oauthToken | |
}) | |
// The space id you want to check - can be found in your spaces settings | |
const spaceId = '51455' | |
const start = async () => { | |
let componentNames = [] | |
// Some more output, so you see what is going on here | |
console.log('Loading list of components') | |
// load information of first 100 components - otherwise we would need to use paging as 100 is max. | |
let components = await Storyblok.get(`spaces/${spaceId}/components/`, { per_page: 100 }) | |
// loop through all components | |
for (let index = 0, max = components.data.components.length; index < max; index++) { | |
let component = components.data.components[index]; | |
// Some more output, so you see what is going on here | |
let componentObject = { | |
name: component.name, | |
display_name: component.display_name | |
} | |
componentNames.push(componentObject) | |
} | |
console.table(componentNames) | |
} | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment