TermAncestorDescendant

View as Markdown

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

NameTypeRequiredDefaultDescription
Uidstring?NonullTerm UID. Serialized as uid.
Namestring?NonullDisplay name of the term. Serialized as name.
ParentUidstring?NonullUID of the parent term. null at the root level. Serialized as parent_uid.
Depthint?NonullLevel of the term in the hierarchy. Serialized as depth.
ChildrenCountint?NonullNumber of child terms. Serialized as children_count.
ReferencedEntriesCountint?NonullNumber 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}");
}