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 .NET SDKs at https://kontent.ai/learn/net
using Kontent.Ai.Delivery;
// Tip: Use DI to create Delivery client https://kontent.ai/learn/net-register-client
IDeliveryClient client = DeliveryClientBuilder
.WithProjectId("8d20758c-d74c-4f59-ae04-ee928c0816b7")
.Build();
// Gets a specific article and its linked items
// Tip: Create strongly typed models according to https://kontent.ai/learn/net-strong-types
IDeliveryItemResponse<SimpleArticle> response = await client.GetItemAsync<SimpleArticle>("the_origin_of_coffee",
new DepthParameter(1)
);
SimpleArticle item = response.Item;
depth
query parameter to 2 or more.// Tip: Create strongly typed models according to https://kontent.ai/learn/net-strong-types
using System;
using System.Collections.Generic;
using Kontent.Ai.Delivery.Abstractions;
namespace KontentAiModels
{
public partial class Author
{
public const string Codename = "author";
public const string NameCodename = "name";
public const string BioCodename = "bio";
public string Name { get; set; }
public IRichTextContent Bio { get; set; }
}
}
// Tip: Create strongly typed models according to https://kontent.ai/learn/net-strong-types
using System;
using System.Collections.Generic;
using Kontent.Ai.Delivery.Abstractions;
namespace KontentAiModels
{
public partial class SimpleArticle
{
public const string Codename = "simple_article";
public const string TitleCodename = "title";
public const string BodyCodename = "body";
public const string AuthorCodename = "author";
public string Title { get; set; }
public string Body { get; set; }
public IEnumerable<object> Author { get; set; }
public IContentItemSystemAttributes System { get; set; }
}
}