Import content model
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.
// 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();
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
- Sport
- 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.
// 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();
3. Add a content type
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!