Term

View as Markdown

Term

Terms are the fundamental building blocks used to create hierarchical structures and to classify and categorize information systematically.

NameTypeDescription
taxonomyUidstringUID of the taxonomy
termUidstringUID of the term

NoteTerm has no public constructor. Get an instance through stack.taxonomy(taxonomyUid).term(termUid). Calling term() without a UID returns a TermQuery instance instead, for listing multiple terms.

fetch

The fetch method retrieves the details of a specific published term.

NameTypeDescription
localestring

Locale code (for example, mr-in), passed positionally. Omit to retrieve the master locale.

Default: master locale

Validation

locale is an optional positional argument, not a chained setter. It must be passed directly to fetch(locale). There is no client-side validation of the locale code. An invalid or unpublished locale is rejected by the API. See Delivery API Errors.

Behavior

Maps to a single GET request to /taxonomies/{taxonomy_uid}/terms/{term_uid}. The response is unwrapped from response.term. If that key is absent, the raw response is returned as-is.

Example

import contentstack, {BaseTerm} from '@contentstack/delivery-sdk'


interface BlogTerms extends BaseTerm {

  taxonomy_uid: string

  uid: string

}


const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" })


// Master locale

const result = await stack

    .taxonomy(taxonomy_uid)

    .term(term_uid)

    .fetch<BlogTerms>()


// Localized

const localized = await stack

    .taxonomy(taxonomy_uid)

    .term(term_uid)

    .fetch<BlogTerms>('mr-in')

locales

The locales method fetches all published, localized versions of a single term.

Validation

This method takes no parameters. There is no client-side validation. An invalid or nonexistent term UID (set earlier through taxonomy(uid).term(termUid)) is rejected by the API. See Delivery API Errors.

Behavior

Maps to a single GET request to /taxonomies/{taxonomy_uid}/terms/{term_uid}/locales. The response is unwrapped from response.locales. If that key is absent, the raw response is returned as-is.

Example

const result = await stack

    .taxonomy(taxonomy_uid)

    .term(term_uid)

    .locales()

ancestors

The ancestors method fetches all ancestors of a single published term, up to the root.

Validation

This method takes no parameters. There is no client-side validation. An invalid or nonexistent term UID (set earlier through taxonomy(uid).term(termUid)) is rejected by the API. See Delivery API Errors.

Behavior

Maps to a single GET request to /taxonomies/{taxonomy_uid}/terms/{term_uid}/ancestors. The response is unwrapped from response.ancestors. If that key is absent, the raw response is returned as-is.

Example

const result = await stack

    .taxonomy(taxonomy_uid)

    .term(term_uid)

    .ancestors()

descendants

The descendants method fetches all descendants of a single published term.

Validation

This method takes no parameters. There is no client-side validation. An invalid or nonexistent term UID (set earlier through taxonomy(uid).term(termUid)) is rejected by the API. See Delivery API Errors.

Behavior

Maps to a single GET request to /taxonomies/{taxonomy_uid}/terms/{term_uid}/descendants. The response is unwrapped from response.descendants. If that key is absent, the raw response is returned as-is.

Example

const result = await stack

    .taxonomy(taxonomy_uid)

    .term(term_uid)

    .descendants()