• Cheat sheets
  • Documentation
  • API reference
  • Product updates
  • Sign in
Kontent.ai Learn
  • Try Kontent.ai
  • Plan
  • Set up
  • Model
  • Develop
  • Create
Copyright © 2024 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Overview
  • Manage API keys
  • Hello World
  • Hello Web Spotlight
  • Try sample apps
  • Build apps
  • Decide navigation and URLs
  • Environments
    • Overview
    • Migrate from other systems
    • Automate migrations with CLI
    • Import content via API
  • Get Developer Certification

Import content items

Tomas Nosek
34 minutes
Download PDF
  • TypeScript
  • .NET
  • REST
0% complete
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.

1. Define a content type for the content item

Before importing your content, you need to define a content type for the items you want to import. The content type in this example is named Cafe (with the codename and external ID both as cafe) and contains a few elements. To add a content type, send a POST request with these properties:
  • The display name of the new 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.
  • (Optional) The external ID can be used as a unique identifier to retrieve content from a different system. See more about how to use different identifiers.
  • A set of the elements you want to have in your content type.
Don't forget to set your Management API key in the request’s authorization header (or the ManagementClient definition when using an SDK).
After making the request, you’ll get a JSON response like this:
  • JSON

2. Import content to a content item

Importing a content item consists of two tasks. That’s because, technically, each content item is a wrapper that contains language variants. Variants then hold the content. This enables content to be localized but the same approach applies to projects with one language as well.
What content items consist of

2a. Create a content item

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!
Sign in
  • TypeScript
{
  "id": "f15799a1-dff0-5216-a014-e963f9ea6bbc",
  "codename": "cafe",
  "last_modified": "2019-10-08T12:47:27.4261844Z",
  "external_id": "cafe",
  "name": "Cafe",
  "content_groups": [],
  "elements": [
    {
      "name": "Price per unit",
      "guidelines": null,
      "is_required": false,
      "type": "number",
      "id": "965cf18c-998a-456b-bee3-91defdf39782",
      "codename": "price_per_unit"
    },
    {
      "guidelines": "<h2>Keep Guidelines where the creative process happens.</h2>\n<p>These are sample guidelines that you can place for the whole content item. It’s a place where you can include your content brief, voice and tone recommendations or the URL to a wireframe, so the author will have all the relevant instructions at hand before writing a single line.</p>\n<p>Besides overview guidelines, you can include instructions for each particular content element, as you will see below.</p>",
      "type": "guidelines",
      "id": "8816e7d0-ca5e-4cfa-88b4-c1944862ff9f",
      "codename": "n8e317a38_e3bc_4d98_a63d_f1e336c5a9e6"
    },
    {
      "maximum_text_length": null,
      "name": "Street",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "2b7b256c-73cc-4be0-b749-4c410209df02",
      "codename": "street"
    },
    {
      "maximum_text_length": null,
      "name": "City",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "fa17f73a-833c-4cf2-aa7b-3b5c4edad6b3",
      "codename": "city"
    },
    {
      "maximum_text_length": null,
      "name": "Country",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "2b36b05e-5f4f-4630-b502-154f5b3b90c3",
      "codename": "country"
    },
    {
      "maximum_text_length": null,
      "name": "State",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "3638f2cd-3fea-4a4e-a6b6-bdd39f3b9f66",
      "codename": "state"
    },
    {
      "maximum_text_length": null,
      "name": "ZIP Code",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "35ad677a-cfe5-4573-814d-5895e3de8396",
      "codename": "zip_code"
    },
    {
      "maximum_text_length": null,
      "name": "Phone",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "4ec54355-4177-4b29-9a16-b25a7c8fba26",
      "codename": "phone"
    },
    {
      "maximum_text_length": null,
      "name": "Email",
      "guidelines": null,
      "is_required": false,
      "type": "text",
      "id": "9bc4b679-4353-40c7-bcfd-145110ced7d9",
      "codename": "email"
    },
    {
      "asset_count_limit": null,
      "maximum_file_size": null,
      "allowed_file_types": "any",
      "image_width_limit": null,
      "image_height_limit": null,
      "name": "Photo",
      "guidelines": null,
      "is_required": false,
      "type": "asset",
      "id": "1693ecd3-fb15-4d56-975a-4b8dbdedf65b",
      "codename": "photo"
    }
  ]
}
  • Content model
  • Content items
  • Linked content
  • Assets
  • Rich text
// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
import { ManagementClient } from '@kontent-ai/management-sdk';

const client = new ManagementClient({
    environmentId: 'KONTENT_AI_ENVIRONMENT_ID',
    apiKey: 'KONTENT_AI_MANAGEMENT_API_KEY'
});

const response = await client
    .addContentType()
    .withData((builder) => {
        return {
            codename: 'cafe',
            name: 'Cafe',
            external_id: 'cafe',
            elements: [
                builder.numberElement({
                    name: 'Price per unit',
                    type: 'number',
                    codename: 'price_per_unit'
                }),
                builder.guidelinesElement({
                    guidelines:
                        '<h2>Keep Guidelines where the creative process happens.</h2>\n<p>These are sample guidelines that you can place for the whole content item. It’s a place where you can include your content brief, voice and tone recommendations or the URL to a wireframe, so the author will have all the relevant instructions at hand before writing a single line.</p>\n<p>Besides overview guidelines, you can include instructions for each particular content element, as you will see below.</p>',
                    type: 'guidelines',
                    codename: 'n2f836bce_e062_b2cd_5265_f5c3be3aa6f5'
                }),
                builder.textElement({
                    name: 'Street',
                    type: 'text',
                    codename: 'street'
                }),

                builder.textElement({
                    name: 'City',
                    type: 'text',
                    codename: 'city'
                }),
                builder.textElement({
                    name: 'Country',
                    type: 'text',
                    codename: 'country'
                }),
                builder.textElement({
                    name: 'State',
                    type: 'text',
                    codename: 'state'
                }),
                builder.textElement({
                    name: 'ZIP Code',
                    type: 'text',
                    codename: 'zip_code'
                }),
                builder.textElement({
                    name: 'Phone',
                    type: 'text',
                    codename: 'phone'
                }),
                builder.textElement({
                    name: 'Email',
                    type: 'text',
                    codename: 'email'
                }),
                builder.assetElement({
                    name: 'Photo',
                    type: 'asset',
                    codename: 'photo'
                })
            ]
        };
    })
    .toPromise();
  • 1. Define a content type for the content item
  • 2. Import content to a content item