Last active
July 11, 2022 18:36
-
-
Save rishi-raj-jain/cbf3ef151c41ec33aa21797d5a86ff25 to your computer and use it in GitHub Desktop.
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
const { data } = require("./data"); | |
const StoryblokClient = require("storyblok-js-client"); | |
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
const Storyblok = new StoryblokClient({ | |
oauthToken: "", | |
}); | |
const spaceId = 164462; | |
const main = async () => { | |
await Storyblok.post(`spaces/${spaceId}/components/`, { | |
component: { | |
name: "new-product", | |
display_name: "New Product", | |
schema: { | |
description: { | |
type: "text", | |
}, | |
prices: { | |
type: "text", | |
}, | |
price: { | |
type: "text", | |
}, | |
images: { | |
type: "text", | |
}, | |
}, | |
}, | |
}); | |
for (const i of data) { | |
await delay(2000); | |
await Storyblok.post(`spaces/${spaceId}/stories/`, { | |
story: { | |
name: i.name, | |
slug: i.slug, | |
default_root: "products", | |
is_folder: false, | |
content: { | |
component: "new-product", | |
description: i.description, | |
prices: JSON.stringify(i.prices), | |
price: JSON.stringify(i.price), | |
images: JSON.stringify(i.images), | |
}, | |
}, | |
publish: 1, | |
}); | |
} | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment