depth
query parameter is higher than 0 (the default value is 1) so that the authors will be returned. Note that any other filtering or order you do to the article will not affect what items are returned within the Linked items element.
The following examples show how to retrieve a single article (named The Origin of Coffee) with its author (a linked item).
In the default JSON response, the codename for your author (jane
in our example) appears in the value
of your author
element. If you have multiple authors, they would appear in the same order in the author
element as they do in the UI.
Jane's name and bio appear in the modular_content
collection under her codename. To use Jane within your article, you need to match the codename from the author
element with the values you want to use from the jane
collection.
{
"item": {
"system": {
"id": "4735c956-4be4-482c-b874-bba201a22f44",
"name": "The Origin of Coffee",
"codename": "the_origin_of_coffee",
"language": "en-US",
"type": "simple_article",
"sitemap_locations": [],
"last_modified": "2020-02-03T12:36:02.7767984Z"
},
"elements": {
"title": {
"type": "text",
"name": "Title",
"value": "The Origin of Coffee"
},
"author": {
"type": "modular_content",
"name": "Author",
"value": [
"jane_doe"
]
}
}
},
"modular_content": {
"jane_doe": {
"system": {
"id": "3bf1c09b-4552-4e2c-8de5-ffce79f773e0",
"name": "Jane Doe",
"codename": "jane_doe",
"language": "en-US",
"type": "author",
"sitemap_locations": [],
"last_modified": "2020-02-03T12:30:14.641708Z"
},
"elements": {
# Omitted for brevity
}
}
}
}
}
// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
import { createDeliveryClient } from '@kontent-ai/delivery-sdk';
import { Author } from './models/Author';
import { SimpleArticle } from './models/SimpleArticle';
const deliveryClient = createDeliveryClient({
environmentId: '8d20758c-d74c-4f59-ae04-ee928c0816b7'
});
const response = await deliveryClient.item<SimpleArticle>('the_origin_of_coffee')
.depthParameter(1)
.toPromise();
const article: SimpleArticle = response.data.item;
const author: Author = article.elements.author;
depth
query parameter to 2 or more.// Tip: Create strongly typed models according to https://kontent.ai/learn/strongly-typed-models
import { IContentItem, Elements } from '@kontent-ai/delivery-sdk';
export type Author = IContentItem<{
name: Elements.TextElement;
bio: Elements.RichTextElement;
}>;
// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
import { IContentItem, Elements } from '@kontent-ai/delivery-sdk';
import { Author } from './models/author';
// Tip: Create strongly typed models according to https://kontent.ai/learn/strongly-typed-models
export type SimpleArticle = IContentItem<{
title: Elements.TextElement;
body: Elements.RichTextElement;
author: Elements.LinkedItemsElement<Author>[];
}>;