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) will appear in the value
of your author
element. If you had multiple authors, they would appear in the same order in the author
element as they do in the UI.
Jane's name and bio will appear in the modular_content
collection under her codename. So to use Jane within your article, all you have to do is 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"
]
},
"body": {
"type": "rich_text",
"name": "Body",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>The history of coffee is patchy and full of myth and hearsay. Although it's far more likely that uses for coffee were developed over time and were discovered by people tasting various parts of the cherry, the old fables do add a bit of romance and are very cute.</p>"
}
}
},
"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": {
"name": {
"type": "text",
"name": "Name",
"value": "Jane Doe"
},
"bio": {
"type": "rich_text",
"name": "Bio",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>Jane is a fun-loving writer who enjoys her coffee black as hell, strong as death, and sweet as love.</p>"
}
}
}
}
}
// Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
using Kontent.Ai.Delivery;
// Creates an instance of the delivery client
// ProTip: Use DI for this in your apps 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
// 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.// 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; }
}
}
// 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; }
}
}