TaxonomyModel

View as Markdown

TaxonomyModel

TaxonomyModel holds the details of a taxonomy. To create a taxonomy with the Create method, set Uid, Name, and optionally Description. The API fills the count and date fields when it returns a taxonomy.

When to Use This Class: Use this class to build the request body for a new, updated, or localized taxonomy. Use it to read a fetched taxonomy as a typed object.

Conceptual Role: Acts as the data model that the Taxonomy class serializes under the taxonomy key of a request.

Returns: TaxonomyModel. The details of a taxonomy.

Properties

NameTypeRequiredDefaultDescription
Uidstring?NonullTaxonomy UID, unique in the stack. Set it to create a taxonomy. Serialized as uid.
Namestring?NonullDisplay name of the taxonomy. Set it to create a taxonomy. Serialized as name.
Descriptionstring?NonullDescription of the taxonomy. Serialized as description.
Localestring?NonullLocale code of this version of the taxonomy. Serialized as locale.
TermsCountint?NonullNumber of terms in the taxonomy. The API sets it. Serialized as terms_count.
ReferencedTermsCountint?NonullNumber of terms that entries use. The API sets it. Serialized as referenced_terms_count.
ReferencedEntriesCountint?NonullNumber of entries that use the terms. The API sets it. Serialized as referenced_entries_count.
ReferencedContentTypeCountint?NonullNumber of content types that use the taxonomy. The API sets it. Serialized as referenced_content_type_count.
CreatedAtstring?NonullCreation time as an ISO 8601 string. The API sets it. Serialized as created_at.
UpdatedAtstring?NonullLast update time as an ISO 8601 string. The API sets it. Serialized as updated_at.
Uuidstring?NonullInternal identifier the API returns with the taxonomy. Serialized as uuid.

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, Name, and Description set produces a body with only uid, name, and description.
  • Leave the count, date, and Uuid properties unset when you create or update a taxonomy. The API sets them, and the API reference documents no effect for them in a request.
  • To localize a taxonomy, pass the target locale as the locale query parameter in the collection of Localize. The API reference documents that parameter as the locale the API writes, and documents no effect for the Locale property in a request.

Counts appear only on request.

  • The API returns TermsCount, ReferencedTermsCount, and ReferencedEntriesCount only when you pass the matching include_* query parameter to Fetch or to the taxonomy query. 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

TaxonomyModel 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 builds a model to create a taxonomy, then reads the created taxonomy 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>");
Stack stack = client.Stack("<API_KEY>");

try
{
    TaxonomyModel model = new TaxonomyModel
    {
        Uid = "product_category",
        Name = "Product Category",
        Description = "Categories for the product catalog"
    };
    ContentstackResponse response = stack.Taxonomy().Create(model);

    TaxonomyModel? created = response.OpenJsonObjectResponse()["taxonomy"]?.Deserialize<TaxonomyModel>();
    Console.WriteLine($"Created {created?.Uid} at {created?.CreatedAt}");
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request, for example a duplicate UID
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}