如何在 Kentico Kontent Management Api v2 上创建组选项卡

问题描述

所以我现在尝试了各种方法

我试过这个json

   {
        name: "Bla bla",type: "group-tab",external_id: "some_key_that_is_unique_gUID"
    }

那没有用。它抱怨 group-tab 不是有效类型。如果我不使用它,那么它会抱怨该值是强制性的。 SDK 允许我省略类型。

如何创建组以及组选项卡的有效类型是什么。

解决方法

我假设您想创建包含内容组的内容类型,对吗?

如果是这样,您需要将 POST 请求与正文一起发送到 https://manage.kontent.ai/v2/projects/{project_id}/types

"external_id": "article","name": "Article","codename": "my_article","content_groups": [
{
"name": "Article copy","external_id": "article-copy"
},{
"name": "Author","codename": "author"
}
],"elements": [
{
"name": "Article title","codename": "title","type": "text","content_group": {
"external_id": "article-copy"
}
},{
"name": "Article body","codename": "body","type": "rich_text",{
"name": "Author bio","codename": "bio","allowed_blocks": [
"images","text"
],"content_group": {
"codename": "author"
}
}
]
}

请注意 JSON 根中的 "content_groups":[...] 字段以及每个元素的特定内容组。

另外,不要忘记添加auth header。您可以在 documentation 中找到更多信息。

注意:我假设(根据您披露的有效负载),API 正确地抱怨 group_tab 不是有效类型,因为您可能使用了错误的端点 - 在这里不确定,因为您没有发布整个请求。>

,

应在通过 Management API v2 添加新内容类型时创建内容组(此处的文档:https://docs.kontent.ai/reference/management-api-v2#operation/add-a-content-type

从文档示例中,“文章副本”和“作者”内容组被添加到新创建的“文章”内容类型中,并且在每个元素中引用这些组以指示相应元素应属于哪个组。

在文档中的示例中,重点关注:

"content_groups": [
   {
     "name": "Article copy","external_id": "article-copy"
   },{
     "name": "Author","codename": "author"
   }
 ],

在数据和:

"content_group": {
       "external_id": "article-copy"
     }

对于元素数组中的每个元素。

    curl --request POST \
  --url https://manage.kontent.ai/v2/projects/<YOUR_PROJECT_ID>/types
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-type: application/json' \
  --data '
{
 "external_id": "article","content_groups": [
   {
     "name": "Article copy","elements": [
   {
     "name": "Article title","content_group": {
       "external_id": "article-copy"
     }
   },{
     "name": "Article body",{
     "name": "Author bio","allowed_blocks": [
        "images","text"
        ],"content_group": {
       "codename": "author"
     }
   }
 ]
}'