Entry
Entry
Entry represents one entry of a content type. Use this class to
- fetch a single published entry by its UID
- shape the response with references, field lists, a locale, and entry variants
- read fields and system values from the entry that Fetch returns
The class has no public constructor. Create an instance with the Entry method of ContentType, which takes the parameter below:
| Name | Type | Description |
|---|---|---|
| entryUid | string | UID of the entry to fetch. |
AddParam
AddParam adds a query parameter of your choice to the Fetch request.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Name of the query parameter to send. |
| value (required) | string | Value of the query parameter. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the name or the value.
- Throws EntryException at once if key is null, or if this entry already holds a parameter named key. The Include methods, SetLocale, Only, and Except each hold their own key, so AddParam("locale", ...) after SetLocale throws.
- A null value sends the parameter with an empty value.
- Fetch throws EntryException if key is environment, because the SDK already sends the client's environment under that name.
- The API rejects an invalid parameter, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. AddParam stores key=value for the query string of the next Fetch call and makes no request.
- Use it for a Content Delivery API parameter that has no method of its own on Entry, for example include_all and include_all_depth from Include all references.
- The SDK writes the name and value into the query string as given, without URL encoding. Encode a value that contains &, =, #, or a space with Uri.EscapeDataString before you pass it.
- See the AddParam method of Query for the same option on a list of entries.
Example
Basic usage: include every referenced entry
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.AddParam("include_all", "true")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}All parameters: include references two levels deep
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.AddParam("include_all", "true")
.AddParam("include_all_depth", "2")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Edge case: a parameter name that another method already set
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry entry = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").IncludeFallback();
try
{
entry.AddParam("include_fallback", "true");
}
catch (EntryException e)
{
// Thrown at once, because IncludeFallback already set include_fallback
Console.WriteLine(e.Message);
}AssetFields
AssetFields requests extra field groups for the assets that the entry references.
| Name | Type | Description |
|---|---|---|
| fields (required) | string[] | Asset field groups to add to the response. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the field group names.
- A null or empty fields leaves the request unchanged.
- Throws ArgumentException at once on a second call on the same entry. Pass every field group in one call.
- The API rejects an invalid value, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. AssetFields stores each value as an asset_fields[] query parameter for the next Fetch call and makes no request.
- fields is a params array, so you can pass the names as separate arguments or as one string[].
- visual_markups returns the hotspot and bounding-box annotations of each embedded asset under the visual_markups key. See Get a single entry for the field groups the API supports.
- The SDK passes every value through as given.
- See the AssetFields method of Query for the same option on a list of entries.
Example
Basic usage: request the visual markups of embedded assets
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.AssetFields("visual_markups")
.Fetch<Entry>();
Console.WriteLine(entry.ToJson());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}All parameters: pass the field groups as one array
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
string[] fieldGroups = new string[] { "visual_markups" };
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.AssetFields(fieldGroups)
.Fetch<Entry>();
Console.WriteLine(entry.ToJson());
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Except
Except leaves the named fields out of the fetched entry and returns every other field.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | string[] | UIDs of the fields to leave out. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the field UIDs.
- A null or empty array leaves the request unchanged.
- A second Except call on the same entry has no effect and raises no error. Pass every field UID in one array.
- The API rejects an invalid value, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Except stores each UID as an except[BASE][] query parameter for the next Fetch call and makes no request.
- BASE refers to the top-level fields of the entry. Name a field inside a Group or Modular Blocks field with dot notation, for example seo.description. See Exclude operator in the Content Delivery API reference.
- To leave out fields of referenced entries, use the IncludeExceptReference method instead.
- Use the Only method to name the fields to keep instead of the fields to drop.
- See the Except method of Query for the same option on a list of entries.
Example
Basic usage: drop two fields from the response
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Except(new string[] { "body", "seo" })
.Fetch<Entry>();
Console.WriteLine(entry.Get("body") == null);
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: drop a field inside a Group field
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// Dot notation names the description field inside the seo group.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Except(new string[] { "seo.description" })
.Fetch<Entry>();
Console.WriteLine(entry.Get("seo"));
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Fetch
Fetch retrieves the entry from the Content Delivery API and returns it as an object of type T.
Returns: Task<T>. The requested entry.
Validation
- There is no client-side validation of the content type UID, the entry UID, or the chained options.
- Throws EntryException, a subclass of ContentstackException, when the API rejects the request, for example for an unknown entry UID or an invalid delivery token. Message, ErrorCode, StatusCode, and Errors carry the error details from the API.
- Throws EntryException with ErrorCode 0 when the response holds no entry object. An empty or null entry UID causes this, because the SDK then requests the entry list path instead of one entry.
- Throws LivePreviewException when live preview is on for this content type and the live preview configuration holds neither a preview token nor a management token.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Fetch sends one GET /content_types/{content_type_uid}/entries/{entry_uid} request. The query string carries the client's environment and every option you chained before the call. See Get a single entry in the Content Delivery API reference.
- The API returns the latest published version of the entry.
- The type argument decides what you get back:
- Fetch does not fill the object you call it on. That object keeps its options, so a second Fetch call sends the same request again.
- The request carries the client headers, the content type headers, and the headers set on this entry. A header set on the entry replaces one of the same name from the content type or the client.
- The client's Branch option sends a branch header, unless Variant or SetHeader sets a branch header on this entry.
- When live preview is on for this content type, Fetch adds the live_preview query parameter and sends the preview or management token. See LivePreviewConfig.
- A reference field holds only the UIDs of the referenced entries unless you chain IncludeReference.
Example
Basic usage: fetch an entry and read its title
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Map the entry onto your own model class
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Product product = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Product>();
Console.WriteLine($"{product.Title}: {product.Url}");
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}
public class Product
{
public string Uid { get; set; }
public string Title { get; set; }
public string Url { get; set; }
}Edge case: read the result, not the request object
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry request = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").SetLocale("<LOCALE>").IncludeFallback();
try
{
Entry entry = await request.Fetch<Entry>();
// Fetch returns a new object. The request object still holds no title.
Console.WriteLine(request.GetTitle() == null);
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Get
Get returns the value of one top-level field of a fetched entry.
| Name | Type | Description |
|---|---|---|
| key (required) | string | UID of the field to read. |
Returns: object. The value of the requested field.
Validation
- There is no client-side validation.
- Get returns null for a field the entry does not hold, and for a null key. It does not throw.
Behavior
- Client-side only. Get reads the response that Fetch stored and makes no request.
- Call it on the Entry that Fetch<Entry>() returns. On the request object from ContentType.Entry, it returns null for every field.
- The return type depends on the JSON value:
- text: string
- number: int, long, or double
- true or false: bool
- object, such as a Group field or publish_details: Dictionary<string, object>
- array, such as a multiple field or a reference field: List<object>
- null: null
- Get reads top-level keys only. Read a nested value from the dictionary or list it returns.
- For a typed result, map the entry onto your own class with Fetch<T> instead.
Example
Basic usage: read a text field
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
string url = entry.Get("url") as string;
Console.WriteLine(url ?? "The entry has no url field");
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Read a nested value from a Group field
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
if (entry.Get("seo") is Dictionary<string, object> seo && seo.TryGetValue("title", out object seoTitle))
Console.WriteLine(seoTitle);
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}GetContentType
GetContentType returns the UID of the content type that the entry belongs to.
Returns: string. The UID of the entry's content type.
Validation
- There is no client-side validation.
- Throws NullReferenceException on an Entry that the SDK built while mapping your own model class, such as an Entry-typed property. That object holds no content type.
Behavior
- Client-side only. GetContentType makes no request.
- It works on both kinds of Entry object: the request object from ContentType.Entry, and the result of Fetch or of Find on a Query.
- The value is the content type UID you passed to client.ContentType, not a value read from the response.
Example
Basic usage: read the content type UID
using System;
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry entry = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>");
Console.WriteLine(entry.GetContentType());GetCreateAt
GetCreateAt returns the creation time of the entry, from the created_at field of a fetched entry.
Returns: DateTime. The entry's creation time.
Validation
- There is no client-side validation.
- GetCreateAt returns DateTime.MinValue when the entry has no created_at field or the value is not a date. It does not throw.
Behavior
- Client-side only. GetCreateAt reads the response that Fetch stored and makes no request.
- The SDK parses the value with DateTime.Parse. A timestamp with a time zone, such as a Z suffix, comes back converted to the local time zone of the machine, with DateTimeKind.Local. Call ToUniversalTime() for UTC.
- On the request object from ContentType.Entry, it returns DateTime.MinValue.
- Use the GetUpdateAt method for the time of the last update.
Example
Basic usage: read the creation time in UTC
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
DateTime createdAt = entry.GetCreateAt();
if (createdAt == DateTime.MinValue)
Console.WriteLine("No creation time in the response");
else
Console.WriteLine(createdAt.ToUniversalTime().ToString("o"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetCreatedBy
GetCreatedBy returns the UID of the user who created the entry, from the created_by field of a fetched entry.
Returns: string. The UID of the user who created the entry.
Validation
- There is no client-side validation.
- GetCreatedBy returns null when the entry has no created_by field. It does not throw.
Behavior
- Client-side only. GetCreatedBy reads the response that Fetch stored and makes no request.
- On the request object from ContentType.Entry, it returns null.
- The GetUpdatedBy method returns an empty string, not null, for a missing field. Check both with string.IsNullOrEmpty.
Example
Basic usage: read the creator UID
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
string createdBy = entry.GetCreatedBy();
Console.WriteLine(string.IsNullOrEmpty(createdBy) ? "No creator in the response" : createdBy);
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetDeletedAt
GetDeletedAt returns the value of the deleted_at field of a fetched entry as a date.
Returns: DateTime. The entry's deletion time.
Validation
- There is no client-side validation.
- GetDeletedAt returns DateTime.MinValue when the entry has no deleted_at field or the value is not a date. It does not throw.
Behavior
- Client-side only. GetDeletedAt reads the response that Fetch stored and makes no request.
- The SDK parses the value with DateTime.Parse. A timestamp with a time zone, such as a Z suffix, comes back converted to the local time zone of the machine.
- Compare the result with DateTime.MinValue before you use it.
- Use the GetDeletedBy method for the UID of the user who deleted the entry.
Example
Basic usage: check for a deletion time
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
DateTime deletedAt = entry.GetDeletedAt();
Console.WriteLine(deletedAt == DateTime.MinValue ? "No deletion time in the response" : deletedAt.ToString("o"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetDeletedBy
GetDeletedBy returns the value of the deleted_by field of a fetched entry.
Returns: string. The UID of the user who deleted the entry.
Validation
- Throws KeyNotFoundException when the entry has no deleted_by field, unlike the other getters on Entry, which return an empty value.
- On the request object from ContentType.Entry, it also throws KeyNotFoundException.
Behavior
- Client-side only. GetDeletedBy reads the response that Fetch stored and makes no request.
- To read the field without the exception, use the Get method, which returns null for a missing field.
Example
Basic usage: read the field safely
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
// Get returns null for a missing field. GetDeletedBy would throw.
Console.WriteLine(entry.Get("deleted_by") == null ? "No deleted_by field" : entry.GetDeletedBy());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetHTMLText
GetHTMLText converts the Markdown in one field of a fetched entry to HTML.
| Name | Type | Description |
|---|---|---|
| markdownKey (required) | string | UID of the Markdown field to convert. |
Returns: string. The field's Markdown rendered as HTML.
Validation
- Throws ArgumentNullException if markdownKey is null.
- GetHTMLText returns an empty string when the entry has no such field or the field value is null. It does not throw in either case.
Behavior
- Client-side only. GetHTMLText reads the response that Fetch stored and makes no request.
- The SDK converts the text with the Markdig library, with its advanced extensions turned on, such as tables and task lists.
- On a Markdown field that holds multiple values, GetHTMLText does not convert the values. It converts the name of the list type instead. See the GetMultipleHTMLText method for multiple-value fields.
- GetHTMLText handles Markdown fields only. To render a Rich Text Editor field with its embedded items, see the includeEmbeddedItems method.
Example
Basic usage: convert a Markdown field to HTML
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
string html = entry.GetHTMLText("description");
Console.WriteLine(html.Length == 0 ? "No Markdown in the description field" : html);
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetMetadata
GetMetadata returns the metadata of a fetched entry.
Returns: Dictionary<string, object>. The entry's metadata.
Validation
- There is no client-side validation.
- GetMetadata returns null when the response has no _metadata key. It does not throw.
Behavior
- Client-side only. GetMetadata returns the Metadata property, which the SDK fills from the _metadata key of the response. It makes no request.
- The API returns _metadata only when the request asks for it. Chain the IncludeMetadata method before Fetch. See Get a single entry in the Content Delivery API reference.
- Nested objects come back as Dictionary<string, object> and arrays as List<object>.
Example
Basic usage: list the metadata keys
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeMetadata()
.Fetch<Entry>();
Dictionary<string, object> metadata = entry.GetMetadata();
Console.WriteLine(metadata == null ? "No metadata" : string.Join(", ", metadata.Keys));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetMultipleHTMLText
GetMultipleHTMLText converts each value of a multiple-value Markdown field to HTML.
| Name | Type | Description |
|---|---|---|
| markdownKey (required) | string | UID of the multiple-value Markdown field. |
Returns: List<string>. The field's Markdown values rendered as HTML.
Validation
- Throws ArgumentNullException if markdownKey is null.
- GetMultipleHTMLText returns an empty list when the entry has no such field or the value is not a list of values. It does not throw.
Behavior
- Client-side only. GetMultipleHTMLText reads the response that Fetch stored and makes no request.
- The SDK converts each value with the Markdig library, with its advanced extensions turned on, and keeps the order of the values.
- Use the GetHTMLText method for a single-value Markdown field.
Example
Basic usage: convert a multiple-value Markdown field
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
List<string> sections = entry.GetMultipleHTMLText("sections");
Console.WriteLine($"{sections.Count} sections converted");
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Workaround: convert the values with Markdig
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using Markdig;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
// The same pipeline the SDK uses. Markdig installs with the SDK.
MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
List<string> sections = new List<string>();
if (entry.Get("sections") is List<object> values)
{
foreach (object value in values)
sections.Add(Markdown.ToHtml(value?.ToString() ?? string.Empty, pipeline));
}
Console.WriteLine($"{sections.Count} sections converted");
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}GetTags
GetTags returns the tags of a fetched entry.
Returns: object[]. The entry's tags.
Validation
- There is no client-side validation.
- GetTags returns null when the entry has no tags field. It does not throw.
Behavior
- Client-side only. GetTags reads the response that Fetch stored and makes no request.
- GetTags does not read the Tags property, so a value from the SetTags method does not change its result.
Example
Basic usage: read the tags
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
object[] tags = entry.GetTags();
Console.WriteLine(tags == null ? "No tags returned" : string.Join(", ", tags));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Workaround: read the tags with Get
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
if (entry.Get("tags") is List<object> tags)
Console.WriteLine(string.Join(", ", tags));
else
Console.WriteLine("The entry has no tags");
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}GetTitle
GetTitle returns the title of a fetched entry.
Returns: string. The entry's title.
Validation
- There is no client-side validation.
- GetTitle returns null when the entry has no title field. It does not throw.
Behavior
- Client-side only. GetTitle returns the Title property, which the SDK fills from the title field of the response. It makes no request.
- On the request object from ContentType.Entry, it returns null. Call it on the Entry that Fetch returns.
Example
Basic usage: print the title
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: the request object holds no title
using System;
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry request = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>");
// Prints True: no Fetch result has filled this object.
Console.WriteLine(request.GetTitle() == null);GetUid
GetUid returns the UID of the entry.
Returns: string. The entry's UID.
Validation
- There is no client-side validation.
Behavior
- Client-side only. GetUid returns the Uid property and makes no request.
- It works on both kinds of Entry object:
Example
Basic usage: read the UID of a fetched entry
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
Console.WriteLine(entry.GetUid());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetUpdateAt
GetUpdateAt returns the last update time of the entry, from the updated_at field of a fetched entry.
Returns: DateTime. The entry's last update time.
Validation
- There is no client-side validation.
- GetUpdateAt returns DateTime.MinValue when the entry has no updated_at field or the value is not a date. It does not throw.
Behavior
- Client-side only. GetUpdateAt reads the response that Fetch stored and makes no request.
- The SDK parses the value with DateTime.Parse. A timestamp with a time zone, such as a Z suffix, comes back converted to the local time zone of the machine, with DateTimeKind.Local. Call ToUniversalTime() for UTC.
- On the request object from ContentType.Entry, it returns DateTime.MinValue.
- Use the GetCreateAt method for the creation time.
Example
Basic usage: read the last update time in UTC
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
DateTime updatedAt = entry.GetUpdateAt();
if (updatedAt == DateTime.MinValue)
Console.WriteLine("No update time in the response");
else
Console.WriteLine(updatedAt.ToUniversalTime().ToString("o"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}GetUpdatedBy
GetUpdatedBy returns the UID of the user who last updated the entry, from the updated_by field of a fetched entry.
Returns: string. The UID of the user who last updated the entry.
Validation
- There is no client-side validation.
- GetUpdatedBy returns an empty string when the entry has no updated_by field. It does not throw.
Behavior
- Client-side only. GetUpdatedBy reads the response that Fetch stored and makes no request.
- On the request object from ContentType.Entry, it returns an empty string.
- The GetCreatedBy method returns null, not an empty string, for a missing field. Check both with string.IsNullOrEmpty.
Example
Basic usage: read the UID of the last editor
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
string updatedBy = entry.GetUpdatedBy();
Console.WriteLine(string.IsNullOrEmpty(updatedBy) ? "No editor in the response" : updatedBy);
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}IncludeBranch
IncludeBranch adds the _branch key, which names the branch the entry belongs to, to the response.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- Throws EntryException at once on a second call on the same entry, because the entry already holds the parameter.
- The API rejects an invalid request, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeBranch adds include_branch=true to the next Fetch call and makes no request.
- The API returns the unique ID of the branch under the top-level _branch key. See Get a single entry in the Content Delivery API reference.
- IncludeBranch does not choose the branch. The Branch option of the client, or the branch argument of Variant, decides which branch the request reads.
- See the IncludeBranch method of Query for the same option on a list of entries.
Example
Basic usage: read the branch of an entry
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeBranch()
.Fetch<Entry>();
Console.WriteLine(entry.Get("_branch"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}IncludeExceptReference
IncludeExceptReference expands one reference field and leaves the named fields out of its referenced entries.
| Name | Type | Description |
|---|---|---|
| keys (required) | string[] | Fields of the referenced entries to leave out. |
| referenceKey (required) | string | UID of the reference field. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of keys or referenceKey.
- A null or empty keys leaves the request unchanged.
- A second call for the same referenceKey has no effect and raises no error.
- The API rejects an invalid value, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeExceptReference stores each key as an except[<referenceKey>][] query parameter for the next Fetch call and makes no request.
- When the entry has no include[] parameter yet, IncludeExceptReference also adds referenceKey as include[], so the API expands that field.
- When the entry already has an include[] parameter, from IncludeReference or an earlier IncludeExceptReference call, IncludeExceptReference leaves it as it is. To trim two reference fields, call IncludeReference with both field UIDs first.
- A later IncludeReference call has no effect, because the include[] parameter already exists.
- See Exclude operator in the Content Delivery API reference for the rules of except[<reference_field_uid>][].
- To leave out top-level fields of the entry itself, use the Except method.
- See the IncludeExceptReference method of Query for the same option on a list of entries.
Example
Basic usage: drop the body of each referenced author
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeExceptReference(new string[] { "body" }, "author")
.Fetch<Entry>();
Console.WriteLine(entry.Get("author"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: trim two reference fields
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// Without the IncludeReference call, only author would be expanded.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference(new string[] { "author", "category" })
.IncludeExceptReference(new string[] { "body" }, "author")
.IncludeExceptReference(new string[] { "description" }, "category")
.Fetch<Entry>();
Console.WriteLine(entry.Get("category"));
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}IncludeFallback
IncludeFallback returns the entry from the fallback locale when the requested locale has no published version.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- Throws EntryException at once on a second call on the same entry, because the entry already holds the parameter.
- The API rejects an invalid request, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeFallback adds include_fallback=true to the next Fetch call and makes no request.
- The API then returns the published content of the fallback locale when the locale you set has none. See Get a single entry in the Content Delivery API reference.
- Pair it with the SetLocale method, which names the locale to request.
- See the IncludeFallback method of Query for the same option on a list of entries.
Example
Basic usage: fall back when a locale has no published version
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.SetLocale("<LOCALE>")
.IncludeFallback()
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}IncludeMetadata
IncludeMetadata adds the entry's metadata to the response.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- Throws EntryException at once on a second call on the same entry, because the entry already holds the parameter.
- The API rejects an invalid request, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeMetadata adds include_metadata=true to the next Fetch call and makes no request.
- The API returns the metadata under the _metadata key of the entry and groups it by extension UID. See Get a single entry in the Content Delivery API reference.
- On a fetched Entry, read it with the GetMetadata method or the Metadata property.
- See the IncludeMetadata method of Query for the same option on a list of entries.
Example
Basic usage: fetch an entry with its metadata
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeMetadata()
.Fetch<Entry>();
Dictionary<string, object> metadata = entry.GetMetadata();
Console.WriteLine(metadata == null ? "No metadata" : string.Join(", ", metadata.Keys));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}IncludeOnlyReference
IncludeOnlyReference limits the referenced entries in one reference field to the fields you name.
| Name | Type | Description |
|---|---|---|
| keys (required) | string[] | Fields of the referenced entries to keep. |
| referenceKey (required) | string | UID of the reference field. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of keys or referenceKey.
- A null or empty keys leaves the request unchanged.
- A second call for the same referenceKey has no effect and raises no error.
- Without an earlier IncludeReference call, a second IncludeOnlyReference call for a different reference field throws ArgumentException at once. Calling IncludeReference first avoids it.
- The API rejects an invalid value, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeOnlyReference stores each key as an only[<referenceKey>][] query parameter for the next Fetch call and makes no request.
- The API applies the field list only to a reference field that the request also expands. See Only operator in the Content Delivery API reference.
- To limit the top-level fields of the entry itself, use the Only method.
- See the IncludeOnlyReference method of Query for the same option on a list of entries.
Example
Basic usage: keep only the title of each author
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// IncludeReference expands the field. IncludeOnlyReference trims it.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference("author")
.IncludeOnlyReference(new string[] { "title" }, "author")
.Fetch<Entry>();
Console.WriteLine(entry.Get("author"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: trim two reference fields
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// Name both fields in one IncludeReference call, then trim each one.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference(new string[] { "author", "category" })
.IncludeOnlyReference(new string[] { "title" }, "author")
.IncludeOnlyReference(new string[] { "title", "url" }, "category")
.Fetch<Entry>();
Console.WriteLine(entry.Get("category"));
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}IncludeOwner
IncludeOwner requests the owner information of the entry in the response.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- Throws EntryException at once on a second call on the same entry, because the entry already holds the parameter.
- The API rejects an invalid request, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeOwner adds the include_owner query parameter to the next Fetch call and makes no request.
- The SDK sends the parameter value as True.
- On a fetched Entry, the ToJson method returns the full response for the entry, including any owner details.
- See the IncludeOwner method of Query for the same option on a list of entries.
Example
Basic usage: request the owner details
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeOwner()
.Fetch<Entry>();
Console.WriteLine(entry.ToJson());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}IncludeReference
IncludeReference returns the content of referenced entries in place of their UIDs, for the reference fields you name.
| Name | Type | Description |
|---|---|---|
| referenceField (required) | string | UID of the reference field to expand. |
| referenceFields (required) | string[] | UIDs of the reference fields to expand. |
Returns: Entry. The same entry, for chaining.
Overloads
- IncludeReference(string referenceField)
- IncludeReference(string[] referenceFields)
Validation
- There is no client-side validation of the field UIDs.
- A null or empty value leaves the request unchanged.
- Only the first IncludeReference call on an entry takes effect. A second call, with either overload, has no effect and raises no error. Pass every reference field in one array.
- The API rejects an invalid value, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeReference stores each UID as an include[] query parameter for the next Fetch call and makes no request.
- Without this option, a reference field holds only the UIDs of the referenced entries. See Include Reference in the Content Delivery API reference.
- Name a reference field inside a Group or Modular Blocks field with dot notation, for example bank_offers.bank. See Include Reference Within Group.
- On a fetched Entry, Get returns an expanded reference field as a List<object>, with each referenced entry as a Dictionary<string, object>.
- The IncludeOnlyReference and IncludeExceptReference methods also write the include[] parameter. Call IncludeReference before either of them. If they run first, the IncludeReference call has no effect.
- To expand every reference field, use the AddParam method with include_all.
- See the IncludeReference method of Query for the same option on a list of entries.
Example
Basic usage: expand one reference field
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference("author")
.Fetch<Entry>();
if (entry.Get("author") is List<object> authors)
{
foreach (object item in authors)
{
if (item is Dictionary<string, object> author)
Console.WriteLine(author["title"]);
}
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}All parameters: expand several reference fields in one call
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// A second IncludeReference call would have no effect, so name every field here.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference(new string[] { "author", "category" })
.Fetch<Entry>();
Console.WriteLine(entry.Get("category"));
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Edge case: expand a reference field inside a Group field
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference("bank_offers.bank")
.Fetch<Entry>();
Console.WriteLine(entry.Get("bank_offers"));
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}IncludeReferenceContentTypeUID
IncludeReferenceContentTypeUID requests the content type UID of each referenced entry in the response.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- Throws EntryException at once on a second call on the same entry, because the entry already holds the parameter.
- The API rejects an invalid request, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeReferenceContentTypeUID adds the include_reference_content_type_uid query parameter to the next Fetch call and makes no request.
- The SDK sends the parameter value as True.
- Combine it with the IncludeReference method when you need both the content and the content type of each referenced entry.
- See the IncludeReferenceContentTypeUID method of Query for the same option on a list of entries.
Example
Basic usage: request the content type UIDs of references
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.IncludeReference("author")
.IncludeReferenceContentTypeUID()
.Fetch<Entry>();
Console.WriteLine(entry.Get("author"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Only
Only limits the fetched entry to the named fields.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | string[] | UIDs of the fields to keep. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the field UIDs.
- A null or empty array leaves the request unchanged.
- A second Only call on the same entry has no effect and raises no error. Pass every field UID in one array.
- The API rejects an invalid value, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Only stores each UID as an only[BASE][] query parameter for the next Fetch call and makes no request.
- BASE refers to the top-level fields of the entry. Name a field inside a Group or Modular Blocks field with dot notation, for example seo.title. See Only operator in the Content Delivery API reference.
- To limit the fields of referenced entries, use the IncludeOnlyReference method instead.
- Use the Except method to name the fields to drop instead of the fields to keep.
- See the Only method of Query for the same option on a list of entries.
Example
Basic usage: keep the title and URL only
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Only(new string[] { "title", "url" })
.Fetch<Entry>();
Console.WriteLine($"{entry.GetTitle()}: {entry.Get("url")}");
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: keep one field inside a Group field
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// Dot notation names the title field inside the seo group.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Only(new string[] { "title", "seo.title" })
.Fetch<Entry>();
Console.WriteLine(entry.Get("seo"));
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}RemoveHeader
RemoveHeader deletes a header from the headers that SetHeader and Variant write on this entry.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Name of the header to remove. |
Returns: void. This method returns nothing.
Validation
- Throws ArgumentNullException if key is null.
- A name that the entry does not hold leaves the entry unchanged and raises no error.
Behavior
- Client-side only. RemoveHeader changes the headers the next Fetch call sends and makes no request.
- It removes only headers set on this entry by SetHeader or Variant. Headers from the content type or the client, such as api_key and access_token, stay in place.
- Removing x-cs-variant-uid makes Fetch return the base entry again.
Example
Basic usage: drop a variant before the next fetch
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry request = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Variant("<VARIANT_UID>");
try
{
Entry variantEntry = await request.Fetch<Entry>();
Console.WriteLine(variantEntry.GetTitle());
request.RemoveHeader("x-cs-variant-uid");
Entry baseEntry = await request.Fetch<Entry>();
Console.WriteLine(baseEntry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}SetCachePolicy
SetCachePolicy records a cache policy on the entry.
| Name | Type | Description |
|---|---|---|
| cachePolicy (required) | CachePolicy | Cache policy for the entry's requests. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- C# typing accepts only a CachePolicy value, and the enum has one member, CachePolicy.NetworkOnly.
Behavior
- Client-side only. SetCachePolicy stores the value and makes no request.
- The SDK has no response cache. Fetch sends a network request every time, with or without this call, so SetCachePolicy does not change what Fetch does.
- CachePolicy lives in the Contentstack.Core.Internals namespace.
- See the SetCachePolicy method of Query for the same setting on a query.
Example
Basic usage: set the only available policy
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.SetCachePolicy(CachePolicy.NetworkOnly)
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}SetHeader
SetHeader adds a request header that this entry sends with Fetch.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Name of the header. |
| value (required) | string | Value of the header. |
Returns: void. This method returns nothing.
Validation
- There is no client-side validation of the header name or value.
- SetHeader ignores the call when key or value is null, and raises no error.
- Fetch skips, without an error, a header that .NET does not let a request set directly, such as Content-Type or User-Agent.
Behavior
- Client-side only. SetHeader stores the header on this entry and makes no request.
- A second call with the same key replaces the value.
- A header set on the entry replaces a header of the same name from the content type or the client, for this entry's requests only.
- SetHeader returns nothing, so it does not chain. Call it as a separate statement before Fetch.
- Use the RemoveHeader method to remove a header that this method added.
Example
Basic usage: send a custom header with one entry request
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry request = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>");
request.SetHeader("branch", "<BRANCH>");
try
{
Entry entry = await request.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}SetLocale
SetLocale sets the locale of the entry that Fetch retrieves.
| Name | Type | Description |
|---|---|---|
| Locale (required) | string | Locale code to fetch, such as en-us. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the locale code.
- The API rejects an invalid or unknown locale, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. SetLocale stores the locale query parameter for the next Fetch call and makes no request.
- A second SetLocale call replaces the locale. This differs from the other option methods on Entry.
- The API returns the entry only when it has a published version in that locale. See Get a single entry in the Content Delivery API reference. Chain the IncludeFallback method to get the fallback locale's content instead.
- The parameter name starts with an uppercase L. Write Locale: if you pass it as a named argument.
- See the SetLocale method of Query for the same option on a list of entries.
Example
Basic usage: fetch the entry in one locale
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.SetLocale("<LOCALE>")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: the second locale wins
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// The request asks for <LOCALE> only. The earlier en-us value is gone.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.SetLocale("en-us")
.SetLocale(Locale: "<LOCALE>")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}SetTags
SetTags writes an array of tags to the Tags property of the entry object.
| Name | Type | Description |
|---|---|---|
| tags (required) | string[] | Tags to store on the object. |
Returns: void. This method returns nothing.
Validation
- There is no client-side validation. SetTags accepts null and stores it.
Behavior
- Client-side only. SetTags writes the Tags property and makes no request.
- The tags stay on the local object. Fetch does not send them, and the Content Delivery API cannot write content, so SetTags cannot change the tags of the stored entry.
- The GetTags method does not read the Tags property. Read Tags directly to get the value back.
Example
Basic usage: store tags on a local entry object
using System;
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry entry = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>");
entry.SetTags(new string[] { "featured", "homepage" });
// Read the property, not GetTags.
Console.WriteLine(string.Join(", ", entry.Tags));SetUid
SetUid sets the UID of the entry that Fetch retrieves.
| Name | Type | Description |
|---|---|---|
| uid (required) | string | UID of the entry. |
Returns: void. This method returns nothing.
Validation
- There is no client-side validation.
- An empty or null UID makes the next Fetch call throw EntryException, because the SDK then requests the entry list path instead of one entry.
Behavior
- Client-side only. SetUid writes the Uid property and makes no request.
- The next Fetch call reads the entry with the new UID and keeps every option you chained before.
- SetUid returns nothing, so it does not chain.
Example
Basic usage: reuse one request for two entries
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
Entry request = client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").SetLocale("<LOCALE>");
try
{
Entry first = await request.Fetch<Entry>();
Console.WriteLine(first.GetTitle());
request.SetUid("<ENTRY_UID>");
Entry second = await request.Fetch<Entry>();
Console.WriteLine(second.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}ToJson
ToJson returns the raw JSON of a fetched entry.
Returns: JsonObject. The entry's raw JSON.
Validation
- There is no client-side validation.
- ToJson returns null on the request object from ContentType.Entry. It does not throw.
Behavior
- Client-side only. ToJson returns the entry object of the response that Fetch stored, as a System.Text.Json.Nodes.JsonObject. It makes no request.
- The object holds every field the API returned, including keys that no getter reads, such as _embedded_items and _branch.
- The SDK returns its own stored object, not a copy.
Example
Basic usage: print the entry as JSON
using System;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").Fetch<Entry>();
JsonObject json = entry.ToJson();
Console.WriteLine(json?.ToJsonString());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Variant
Variant fetches the entry with the content of one or more entry variants applied.
| Name | Type | Description |
|---|---|---|
| variant_header (required) | string | Variant UID or variant alias to apply. |
| branch | string | Branch to read the variant from. |
| variant_headers (required) | List<string> | Variant UIDs or aliases, highest priority first. |
Returns: Entry. The same entry, for chaining.
Overloads
- Variant(string variant_header, string branch = null)
- Variant(List<string> variant_headers, string branch = null)
Validation
- There is no client-side validation of the variant UIDs or the branch.
- A null variant_header sends no variant header, so Fetch returns the base entry.
- A null variant_headers list throws ArgumentNullException at once.
- The API rejects an unknown variant or branch, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Variant sets two request headers for the next Fetch call and makes no request:
- x-cs-variant-uid, with the UIDs of a list joined by commas.
- branch, with the branch the SDK resolves from the branch argument.
- The SDK resolves the branch in this order:
- the branch argument, when it is not null, empty, or white space
- the Branch option of the client
- main
- The branch header from Variant replaces the client's Branch option for this entry's requests.
- The API accepts variant aliases in place of variant UIDs. By default it accepts up to five values, and the first one takes priority over the rest. See Get single entry variant in the Content Delivery API reference.
- A second Variant call replaces both headers.
- To go back to the base entry, remove the variant header with the RemoveHeader method.
- See the Variant method of Query for the same option on a list of entries.
Example
Basic usage: fetch one variant of an entry
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Variant("<VARIANT_UID>")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}All parameters: apply a list of variants from a specific branch
using System;
using System.Collections.Generic;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
// List the variant UIDs or aliases in priority order.
List<string> variants = new List<string> { "<VARIANT_UID>" };
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Variant(variants, "<BRANCH>")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Edge case: one variant from a named branch
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// Without the branch argument, the SDK sends the client's Branch option, or main.
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.Variant("<VARIANT_UID>", branch: "<BRANCH>")
.Fetch<Entry>();
Console.WriteLine(entry.GetTitle());
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}includeEmbeddedItems
includeEmbeddedItems adds the entries and assets embedded in the entry's Rich Text Editor (RTE) fields to the response.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation.
- Throws EntryException at once on a second call on the same entry, because the entry already holds the parameter.
- The API rejects an invalid request, and Fetch throws EntryException when it sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. includeEmbeddedItems adds include_embedded_items[]=BASE to the next Fetch call and makes no request. The method name starts with a lowercase i.
- With BASE, the API returns the first level of embedded entries and assets under the _embedded_items key, with one list per RTE field UID. See Get information on embedded RTE objects in the Content Delivery API reference.
- includeEmbeddedItems always sends BASE. For nested embedded items, call the AddParam method instead, as AddParam("include_embedded_items[]", "RECURSIVE"), and add embedded_items_depth the same way if you need a depth limit. Calling both on one entry throws EntryException, because they write the same parameter.
- To render an RTE field as HTML with its embedded items, use the contentstack.utils package, which the SDK installs as a dependency. Map the entry onto a model class that implements its IEntryEmbedable interface. The client registers the converter for embedded objects, so Fetch<T> fills the embeddedItems property. Then pass the field and the model to Utils.RenderContent.
- See the includeEmbeddedItems method of Query for the same option on a list of entries.
Example
Basic usage: fetch an entry with its embedded items
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Entry entry = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.includeEmbeddedItems()
.Fetch<Entry>();
Console.WriteLine(entry.Get("_embedded_items"));
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Render an RTE field as HTML with its embedded items
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Utils;
using Contentstack.Utils.Interfaces;
using Contentstack.Utils.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Article article = await client.ContentType("<CONTENT_TYPE_UID>")
.Entry("<ENTRY_UID>")
.includeEmbeddedItems()
.Fetch<Article>();
// RenderContent replaces each embedded item tag in the field with HTML.
string html = Utils.RenderContent(article.Body, new Options(article));
Console.WriteLine(html);
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}
public class Article : IEntryEmbedable
{
public string Uid { get; set; }
public string Title { get; set; }
public string Body { get; set; }
[JsonPropertyName("_embedded_items")]
public Dictionary<string, List<IEmbeddedObject>> embeddedItems { get; set; }
}