Content items often contain references to other content items in linked items elements or rich text elements. This lesson shows you how to import these references to Kontent.ai.
To avoid having to import objects in a specific order, use external IDs to reference content that’s not yet imported. This solves problems with circular dependencies and lets you reference non-existent content.Here is how it works:
Define external IDs for all content items and assets you want to import in advance.
When referencing another content item or asset, use its external ID.
Import your content using the upsert methods with an external ID. The system will resolve all references.
This way, you can import your content in any order and run the import process repeatedly to keep your project up to date. In the example below, you will import two content items that reference each other in their Linked items elements.Say you want to import two related content items: Donate with us and On Roasts articles. Each content item references the other in the Related articles Linked items element. The result will have the following structure:
External IDs are string-based identifiers of items and assets defined by you. You can define new IDs or reuse IDs from the original storage system you are importing content from.
Send a PUT request to the endpoint specifying the language variant you want to insert or update. In the body of the request, specify the values of individual content elements.
Notice that you are referencing the Donate with us item even though you haven't imported it yet. Such references are not visible in the UI.
Repeat the same process with the Donate with us article. Start by creating the content item:
This resolves the reference in the On Roasts item.
Lastly, import the content of the Donate with us item by upserting its language variant:
Both references are now resolved. To verify, you can view the imported content items in Kontent.ai:
After your import process is finished, we recommend that you validate your project's content for inconsistencies. For example, if you forget to add the second item, the validation will report that you’re referencing a nonexistent object. Project validation can also reveal other issues like references to missing assets or empty required elements.
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!
The reference is not visible inside the Kontent.ai UI, but it still exists. It will resolve itself once you import the second content item.
The Donate with us and On Roasts articles link to one another within their Related articles elements.In Kontent.ai, select Content & assets to view the imported content items.
The Donate with us and On Roasts articles link to one another within their Related articles elements.In Kontent.ai, select Content & assets to view the imported content items.
Rich text links See how to import rich text to learn how to link items in rich text elements.
Best practice: Upsert by external ID You can use a simple POST to /items request to add the content item. But using an UPSERT operation and defining an external ID for your item has advantages and makes the import process much smoother:
You can run the same request repeatedly. If the item doesn't exist, it will be created. If it does, it will be updated.
You can reference or link to your item, even if it hasn't been imported yet (and has no internal ID or codename). You might have other content items that reference this one in Rich text or Linked items elements. But if you are using external IDs you don't need to worry about the order in which the content items are imported.