简体   繁体   中英

How do I create a group tab on Kentico Kontent Management Api v2

So I have tried all sorts now.

I have tried this json

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

That did not work. It complains that group-tab is not a valid type. If I leave it off then it complains that the value is mandatory. The SDK allows me to omit the type.

How do I create a group and what is the valid type for a group tab.

I assume you want to create a content type with content groups, am I right?

If so, you need to send POST request to https://manage.kontent.ai/v2/projects/{project_id}/types with the body:

"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"
}
}
]
}

Please note "content_groups":[...] field in the root of JSON as well as a specific content group for each element.

Also, do not forget to add auth header . You can find more info in the documentation .

Note: I assume (from your disclosed payload), the API is complaining correctly that group_tab is not a valid type, since you probably use the wrong endpoint - not sure here since you didn't post your whole request.

Creating a content group should occur while adding a new content type via the Management API v2 (documentation here: https://docs.kontent.ai/reference/management-api-v2#operation/add-a-content-type )

From the documentation example, "Article Copy" and "Author" content groups are added to the newly created "Article" content type, and the groups are referenced in each element to indicate which group the respective element should fall under.

In the example from the documentation, focus on:

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

in data and:

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

for each element in the elements array.

    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"
     }
   }
 ]
}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM