0

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

我试过这个json

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

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

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

4

2 回答 2

2

我假设您想使用内容组创建内容类型,对吗?

如果是这样,您需要将 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",
      "content_group": {
        "external_id": "article-copy"
      }
    },
    {
      "name": "Author bio",
      "codename": "bio",
      "allowed_blocks": [
        "images",
        "text"
      ],
      "type": "rich_text",
      "content_group": {
        "codename": "author"
      }
    }
  ]
}

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

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

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

于 2021-02-23T18:43:12.170 回答
2

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

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

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

"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",
 "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",
     "content_group": {
       "external_id": "article-copy"
     }
   },
   {
     "name": "Author bio",
     "codename": "bio",
     "allowed_blocks": [
        "images",
        "text"
        ],
     "type": "rich_text",
     "content_group": {
       "codename": "author"
     }
   }
 ]
}'
于 2021-02-23T18:49:53.483 回答