TermAncestorDescendant
TermAncestorDescendant
TermAncestorDescendant holds one term that sits above or below another term in a taxonomy hierarchy. The Ancestors and Descendants lists of TermModel hold objects of this type.
When to Use This Class: Use this class to read the ancestors or descendants of a term as typed objects.
Conceptual Role: Acts as a read-only data model for the hierarchy fields of a term. No SDK method takes it as an argument.
Returns: TermAncestorDescendant. One term in the hierarchy of another term.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Uid | string? | No | null | Term UID. Serialized as uid. |
| Name | string? | No | null | Display name of the term. Serialized as name. |
| ParentUid | string? | No | null | UID of the parent term. null at the root level. Serialized as parent_uid. |
| Depth | int? | No | null | Level of the term in the hierarchy. Serialized as depth. |
| ChildrenCount | int? | No | null | Number of child terms. Serialized as children_count. |
| ReferencedEntriesCount | int? | No | null | Number of entries that carry the term. Serialized as referenced_entries_count. |
Class-Level Notes
Where the values come from.
- The API sets every property. The SDK fills them only when you deserialize a response into TermModel or into this class.
- ChildrenCount and ReferencedEntriesCount stay null unless the request passed include_children_count or include_referenced_entries_count.
- The API reference does not document the response shape of Ancestors and Descendants. Read the body with OpenJsonObjectResponse() and check the keys before you deserialize them.
Method Index
TermAncestorDescendant has no methods. Read its properties directly.
Class-Level Snippet
The snippet below fetches a term and prints the ancestors that the term response holds.
using System;
using System.Collections.Generic;
using System.Text.Json;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Taxonomy("<TAXONOMY_UID>").Terms("<TERM_UID>").Fetch();
TermModel? term = response.OpenJsonObjectResponse()["term"]?.Deserialize<TermModel>();
foreach (TermAncestorDescendant ancestor in term?.Ancestors ?? new List<TermAncestorDescendant>())
{
Console.WriteLine($"Depth {ancestor.Depth}: {ancestor.Name} ({ancestor.Uid})");
}
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}