Kontent.ai
Copyright © 2023 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Documentation
  • API reference
  • Product updates
Kontent.ai Learn
  • Plan
  • Set up
  • Model
  • Develop
  • Create

Import content model

Is this page helpful?
Complete and continue
  • Sign in
    • JavaScript
      JavaScript
    • REST
      REST
    Matus Usiak
    36 minutes
    Learn how to import content model using Management API. You'll go step by step and create a basic content type with several elements, a content type snippet, and a taxonomy.

    Content model overview

    Before creating the content type, create the snippet and taxonomy group. This way you can include them in the type as elements later on. When importing your content, starting with the smaller parts (taxonomy group and snippet with elements) before you tie them together is better. When you think about re-using content, for example, using the same content elements in multiple items, it is easier to create the snippet with those elements and then include the snippet in all types the elements needs to be in. Rather than creating the types and adding the elements to them. In the diagram below, there's a Blogpost type with elements divided in three content groups. The first Content content group has some general fields such as title and blog content. In the Metadata content group, there's a snippet which can be re-used across multiple types. The third group named Topic contains a taxonomy, which can be used for tagging and organizing content.

    1. Add a content type snippet

    Let's start with adding the snippet called Metadata with two elements. To add a snippet, make a POST request with the following properties:
    • Name which serves as a display name of the snippet.
    • An array of content elements you want to have in the snippet.

    2. Add a taxonomy group

    Now you can move onto adding a taxonomy group along with its terms. In this example, the taxonomy is called blogpost topic with terms like sport and technology stack. Both of these terms will serve as subgroups that will hold actual sports and programming languages. Taxonomies allow you to organize your content into hierarchies. The sample taxonomy hierarchy looks like this:
    • Blogpost topic
      • Sport
        • Soccer
        • Ice hockey
        • Rugby
      • Technology stack
        • JavaScript
        • C#
        • MVC
    To add the taxonomy group with its terms, make a POST request with these properties:
    • Name which serves as a display name of the taxonomy group.
    • An array of taxonomy terms which can have more terms within them, like JavaScript under Technology stack.

    3. Add a content type

    Finally, add the content type along with its content groups, as well as the content type snippet and taxonomy group you created earlier.  To add the content type with its elements, make a POST request with these properties:
    • Name which serves as a display name of the content type.
    • (Optional) The codename of the content type. If you don't specify the codename, it will be generated from the content type's display name. However, you can change the codename later.
    • An array of content groups with these properties:
      • Name used as a display name.
      • External ID of the content group. You'll reference the external ID when adding content elements to specific content groups.
    • An array of content elements that define structure of the type.
    What's next?
    Import content items
    This lesson shows you how to import a single content item using Management API. In short, to import content, you define a content type for the imported content if it’s not created already. Then, you’ll create a new content item and add content to its variants.
    • Develop with Kontent.ai
    • Hello World
    • Hello Web Spotlight
    • Run a sample app
    • Build apps
    • Decide navigation and URLs
    • Environments
    • Get Developer Certification
    • Overview
    • Import content via API
    • Automate migrations with CLI
    • PDFs and other formats
    • JavaScript
    • JavaScript
    • JavaScript
    // Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
    // Using ES6 syntax
    import { ManagementClient } from '@kontent-ai/management-sdk';
    
    const client = new ManagementClient({
      environmentId: '<YOUR_ENVIRONMENT_ID>',
      apiKey: '<YOUR_API_KEY>'
    });
    
    const response = client.addContentTypeSnippet()
      .withData(builder => {
        return {
          name: "Metadata",
          codename: "metadata",
          elements: [
            builder.textElement({
              name: "Title",
              codename: "title",
              type: 'text'
            }),
            builder.textElement({
              name: "Keywords",
              codename: "keywords",
              type: 'text'
            }),
            builder.textElement({
              name: "Description",
              codename: "description",
              type: 'text'
            })
          ]
        };
      })
      .toPromise();
    // Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
    // Using ES6 syntax
    import { ManagementClient } from '@kontent-ai/management-sdk';
    
    const client = new ManagementClient({
      environmentId: '<YOUR_ENVIRONMENT_ID>',
      apiKey: '<YOUR_API_KEY>'
    });
    
    const response = client.addTaxonomy()
      .withData(
        {
          name: 'Blogpost topic',
          codename: 'blog_topic',
          terms: [
            {
              name: 'Sport',
              codename: 'sport',
              terms: [
                {
                  name: 'Soccer',
                  codename: 'soccer',
                  terms: []
                },
                {
                  name: 'Ice hockey',
                  codename: 'hockey',
                  terms: []
                },
                {
                  name: 'Rugby',
                  codename: 'rugby',
                  terms: []
                }
              ]
            },
            {
              name: "Technology stack",
              codename: "tech",
              terms: [
                {
                  name: "JavaScript",
                  codename: "js",
                  terms: []
                },
                {
                  name: "C#",
                  codename: "c",
                  terms: []
                },
                {
                  name: 'MVC',
                  codename: 'mvc',
                  terms: []
                }
              ]
            }
          ]
        }
      )
      .toPromise();
    // Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
    // Using ES6 syntax
    import { ManagementClient } from '@kontent-ai/management-sdk';
    
    const client = new ManagementClient({
      environmentId: '<YOUR_ENVIRONMENT_ID>',
      apiKey: '<YOUR_API_KEY>'
    });
    
    const response = client.addContentType()
      .withData(builder => {
        return {
          name: 'Blogpost',
          codename: 'blogpost',
          content_groups: [{
            name: 'Content',
            external_id: 'content'
          },
          {
            name: 'Metadata',
            external_id: 'metadata'
          },
          {
            name: 'Topic',
            external_id: 'topic'
          }
          ],
          elements: [
            builder.textElement({
              name: 'Title',
              type: 'text',
              content_group: {
                external_id: 'content'
              },
            }),
            builder.assetElement({
              name: 'Image',
              type: 'asset',
              content_group: {
                external_id: 'content'
              },
            }),
            builder.richTextElement({
              name: 'Blog content',
              type: 'rich_text',
              content_group: {
                external_id: 'content'
              },
            }),
            builder.snippetElement({
              snippet: {
                'codename': 'metadata'
              },
              type: 'snippet',
              codename: 'metadata',
              content_group: {
                external_id: 'metadata'
              },
            }),
            builder.taxonomyElement({
              taxonomy_group: {
                'codename': 'blog_topic'
              },
              type: 'taxonomy',
              codename: 'taxonomy',
              content_group: {
                external_id: 'topic'
              }
            })
          ]
        };
      })
      .toPromise();
    • Content model
    • Content items
    • Linked content
    • Assets
    • Rich text
  • Content model overview
  • 1. Add a content type snippet
  • 2. Add a taxonomy group
  • 3. Add a content type