【问题标题】:How do I create a group tab on Kentico Kontent Management Api v2如何在 Kentico Kontent Management Api v2 上创建组选项卡
【发布时间】:2021-02-23 17:12:44
【问题描述】:

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

我试过这个json

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

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

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

【问题讨论】:

    标签: kentico kentico-kontent


    【解决方案1】:

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

    如果是这样,您需要发送 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"
          }
        }
      ]
    }
    

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

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

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

    【讨论】:

      【解决方案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"
           }
         }
       ]
      }'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多