TermModel
TermModel
TermModel holds the details of a taxonomy term. To create a term with the Create method, set Uid, Name, and optionally ParentUid. The API fills the depth, count, hierarchy, and date fields when it returns a term.
When to Use This Class: Use this class to build the request body for a new, updated, or localized term. Use it to read a fetched term as a typed object.
Conceptual Role: Acts as the data model that the Term class serializes under the term key of a request.
Returns: TermModel. The details of a taxonomy term.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Uid | string? | No | null | Term UID. Set it to create a term. Serialized as uid. |
| Name | string? | No | null | Display name of the term. Set it to create a term. Serialized as name. |
| TaxonomyUid | string? | No | null | UID of the taxonomy that holds the term. The API sets it. Serialized as taxonomy_uid. |
| ParentUid | string? | No | null | UID of the parent term. null places the term at the root level. Serialized as parent_uid. |
| Depth | int? | No | null | Level of the term in the hierarchy. The API sets it. Serialized as depth. |
| ChildrenCount | int? | No | null | Number of child terms. The API sets it. Serialized as children_count. |
| ReferencedEntriesCount | int? | No | null | Number of entries that carry the term. The API sets it. Serialized as referenced_entries_count. |
| Ancestors | List<TermAncestorDescendant>? | No | null | Terms above this term. The API sets it. Serialized as ancestors. |
| Descendants | List<TermAncestorDescendant>? | No | null | Terms below this term. The API sets it. Serialized as descendants. |
| CreatedAt | string? | No | null | Creation time as an ISO 8601 string. The API sets it. Serialized as created_at. |
| UpdatedAt | string? | No | null | Last update time as an ISO 8601 string. The API sets it. Serialized as updated_at. |
The Ancestors and Descendants lists hold TermAncestorDescendant objects.
Class-Level Notes
Fields you send and fields the API sets.
- The SDK serializes every property that is not null and leaves out the null ones. A model with only Uid and Name set produces a body with only uid and name, which creates a root-level term.
- Leave TaxonomyUid, the counts, Depth, Ancestors, Descendants, and the dates unset in a request. The API sets them, and the API reference documents no effect for them in a request.
Position is not part of the model.
- TermModel has no order property, so Create cannot set the position of a term among its siblings. Call Move with a TermMoveModel after you create the term.
Counts appear only on request.
- The API returns ChildrenCount and ReferencedEntriesCount only when you pass include_children_count or include_referenced_entries_count. The properties stay null otherwise.
Dates are strings.
- CreatedAt and UpdatedAt hold the timestamp string the API returns. Parse them with DateTimeOffset.Parse when you need a date value.
Method Index
TermModel has no methods. Set and read its properties directly, and pass the model to the Create, Update, or Localize method.
Class-Level Snippet
The snippet below creates a child term, then reads it back into a second model.
using System;
using System.Text.Json;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Taxonomy taxonomy = client.Stack("<API_KEY>").Taxonomy("<TAXONOMY_UID>");
try
{
TermModel model = new TermModel
{
Uid = "running_shoes",
Name = "Running Shoes",
ParentUid = "footwear"
};
taxonomy.Terms().Create(model);
ContentstackResponse response = taxonomy.Terms("running_shoes").Fetch();
TermModel? term = response.OpenJsonObjectResponse()["term"]?.Deserialize<TermModel>();
Console.WriteLine($"{term?.Name} sits at depth {term?.Depth} in {term?.TaxonomyUid}");
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects a request, for example an unknown parent term
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}