简体   繁体   English

如何在 js 中导出 storyblok 中的整个空间?

[英]How do I export an entire space in storyblok in js?

From reading up on the management API, I think I should be able to fetch data from storyblok from inside my js.通过阅读管理 API,我认为我应该能够从我的 js 中的 storyblok 获取数据。 The first thing I'm trying is to export my entire space so that I can have an external backup.我要尝试的第一件事是导出我的整个空间,以便我可以进行外部备份。 From reading the documentation, I think the following should work, but it gives me a 401. What is the correct syntax for this?通过阅读文档,我认为以下内容应该有效,但它给了我一个 401。正确的语法是什么?

  // spaceId is discovered in Settings / Space
  fetch(
     `https://mapi.storyblok.com/v2/spaces/${spaceId}/export.json`,
     {
       headers: {
         Authorization: managementToken, // this was created in My Account / Account Settings / Personal access Token
       },
     }
  )
  .then(async (res) => {
    const json = await res.json()
    console.log(json)
  })
  .catch((err) => console.log(err));

I was also looking to export a single story, which I think the correct URL should be:我还想导出一个故事,我认为正确的 URL 应该是:

`https://mapi.storyblok.com/v2/spaces/${spaceId}/stories/${storyId}/export.json`

I can't figure out how to determine the storyId, though.不过,我不知道如何确定 storyId。 I tried the UID but that didn't work and the example showed an 8 digit number.我尝试了 UID,但没有用,示例显示了一个 8 位数字。 Where do I find this number?我在哪里可以找到这个号码?

Note: I'm in the US, and for the regular fetches I had to use the domain https://api-us.storyblok.com so I tried adding -us and that didn't work.注意:我在美国,对于常规抓取,我必须使用域https://api-us.storyblok.com所以我尝试添加-us但没有用。

Note: I will eventually be trying to add and modify stories in this same js file.注意:我最终会尝试在同一个 js 文件中添加和修改故事。 Also, be able to "restore" the entire space if necessary.此外,必要时能够“恢复”整个空间。 I hope the solution to the above will be applicable to all the rest of the calls I'll be attempting.我希望上述解决方案适用于我将尝试的所有呼叫 rest。

Note: The app is written in Nuxt 3 and I'm using useStoryblok() successfully to retrieve data.注意:该应用程序是用 Nuxt 3 编写的,我正在使用useStoryblok()成功检索数据。 I could fulfill the above requirement to back up the entire space by iterating through everything there, but that seems like more work than is necessary, and it doesn't solve my problem with the other calls I need to make.我可以通过遍历那里的所有内容来满足上述备份整个空间的要求,但这似乎比必要的工作更多,而且它不能解决我需要进行的其他调用的问题。

The management API is still on v1 , it's only the content API that's v2 : https://www.storyblok.com/docs/api That probably should help with your 401. I actually also assumed I had to use v2 :)管理 API 仍在v1上,只有内容 API 是v2https://www.storyblok.com/docs/api这可能对您的 401 有帮助。实际上我还假设我必须使用v2 :)

As how to get the story ID: yes, it's the simple ID, not the UUID.至于如何获取故事 ID:是的,它是简单的 ID,而不是 UUID。 You get it by listing some stories .../v2/spaces/SPACEID/stories?with_slug=abc .您可以通过列出一些故事来获得它.../v2/spaces/SPACEID/stories?with_slug=abc

Or look at the draft/published JSON in the Storyblok UI.或者在 Storyblok UI 中查看草稿/已发布 JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Vuex 集成到 Storyblok 插件中? - How can I integrate Vuex into a Storyblok plugin? 如何在Javascript / Typescript中使用Storyblok电子邮件服务? - How can I use the Storyblok Email Service in Javascript / Typescript? 如何在节点 js 中使用 module.exports 导出数组? - How do I export an array with module.exports in node js? 如何在 JS React 中使用两个函数导出默认值? - How do I export default with two functions in JS React? 如何使用JS填补可用空间? - How do I use JS to fill up availiable space? 在Node.JS中,如何从单独的.js文件返回整个对象? - In Node.JS, how do I return an entire object from a separate .js file? 如何导出车把文件以及如何将其导入到 JS 文件中 - How do I export a handlebars file and how do i import it in a JS file 如何将“用户”object 从我的 TopBar.js 导出到 App.js? - How do I export "user" object from my TopBar.js to App.js? 仅当regexp匹配整个字符串(无子字符串)时,如何使用JS regexp匹配字符串 - How do I use a JS regexp to match a string only if the regexp matches the entire string(no substring) Discord.js 如何让我的机器人阅读整个句子中的禁用词? - Discord.js How do I make my bot read an entire sentence for banned words?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM