Taxonomy
Taxonomy
Taxonomy organizes the content of a stack into a hierarchy of terms that you tag entries with. Use the Taxonomy class for the four tasks below:
- list the taxonomies published to an environment
- read one published taxonomy by its UID
- reach the terms of that taxonomy
- filter entries by the terms they carry
client.Taxonomies() and client.Taxonomies(uid) on ContentstackClient return a Taxonomy:
| Name | Type | Description |
|---|---|---|
| uid | string | UID of the taxonomy to read. Omit it to list taxonomies or filter entries. |
Taxonomy inherits from Query, so every Query method is also available on a Taxonomy. The pages below cover only the methods that Taxonomy declares itself. The Query class page documents the inherited filters, for example Where, Exists, Or, And, Limit and IncludeCount.
Above
Above matches entries tagged with the ancestors of a term, excluding the term itself.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Taxonomy field path, for example taxonomies.color. |
| value (required) | object | UID of the term whose ancestors to match. |
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- Throws NullReferenceException if key or value is null, because the condition needs both a field path and a term.
- Throws TaxonomyException if the instance already holds a condition on key, because each field path holds one condition. Use the inherited Or or And method to combine two conditions on one field.
- There is no other client-side validation. Above stores an empty key or an unknown term UID as given.
- An invalid value surfaces as a ContentstackException (or a subclass) when Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Above stores the condition { "$above": value } under key and makes no request.
- The match excludes the named term. An entry tagged only with that term does not match. Use the EqualAndAbove method to include it.
- Sends no levels value, so the API matches ancestors up to 10 levels above the term (Above Operator). The Hierarchy levels note on the Taxonomy class page gives the Where workaround that sets the levels.
- Chaining Above makes the following Find call GET /taxonomies/entries, so Find returns entries instead of taxonomies.
Example
Basic usage: match the ancestors of a term
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<Entry> result = await client.Taxonomies()
.Above("taxonomies.<TAXONOMY_UID>", "<TERM_UID>")
.Find<Entry>();
foreach (Entry entry in result)
{
Console.WriteLine(entry.Title);
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Edge case: a second condition on the same field throws
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Taxonomy taxonomy = client.Taxonomies().Above("taxonomies.<TAXONOMY_UID>", "<TERM_UID>");
// The field path already holds the Above condition, so this call throws
taxonomy.EqualAndBelow("taxonomies.<TAXONOMY_UID>", "<TERM_UID>");
}
catch (TaxonomyException e)
{
// Thrown when the field path already holds a condition
Console.WriteLine(e.Message);
}AddParam
AddParam adds one query parameter to Fetch and to the taxonomy list.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Name of the query parameter, for example limit. |
| value (required) | string | Value of the query parameter. |
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- Throws ArgumentNullException if key is null, because the SDK stores parameters in a dictionary keyed by name.
- There is no other client-side validation. A null value sends the parameter with an empty value.
- An invalid value surfaces as a ContentstackException (or a subclass) when Fetch or Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. AddParam stores the pair and makes no request. A second call with the same key replaces the first value.
- Fetch and the taxonomy list from Find send the pair.
- Use it for the parameters this class has no method for, for example skip and limit, which page the taxonomy list (Get all taxonomies).
- Replaces the Query method of the same name. The entry filter does not send this pair. The Known issue notes on the Taxonomy class page give the workaround for the entry filter.
Example
Basic usage: page through the taxonomy list
using System;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<JsonObject> result = await client.Taxonomies()
.AddParam("skip", "0")
.AddParam("limit", "5")
.Find<JsonObject>();
foreach (JsonObject taxonomy in result)
{
Console.WriteLine(taxonomy["uid"]);
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Below
Below matches entries tagged with the descendants of a term, excluding the term itself.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Taxonomy field path, for example taxonomies.color. |
| value (required) | object | UID of the term whose descendants to match. |
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- Throws NullReferenceException if key or value is null, because the condition needs both a field path and a term.
- Throws TaxonomyException if the instance already holds a condition on key, because each field path holds one condition. Use the inherited Or or And method to combine two conditions on one field.
- There is no other client-side validation. Below stores an empty key or an unknown term UID as given.
- An invalid value surfaces as a ContentstackException (or a subclass) when Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Below stores the condition { "$below": value } under key and makes no request.
- The match excludes the named term. An entry tagged only with that term does not match. Use the EqualAndBelow method to include it.
- Sends no levels value, so the API matches descendants up to 10 levels below the term (Below Operator). The Hierarchy levels note on the Taxonomy class page gives the Where workaround that sets the levels.
- Chaining Below makes the following Find call GET /taxonomies/entries, so Find returns entries instead of taxonomies.
Example
Basic usage: match the descendants of a term
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<Entry> result = await client.Taxonomies()
.Below("taxonomies.<TAXONOMY_UID>", "<TERM_UID>")
.Find<Entry>();
foreach (Entry entry in result)
{
Console.WriteLine(entry.Title);
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}EqualAndAbove
EqualAndAbove matches entries tagged with a term or any of its ancestors.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Taxonomy field path, for example taxonomies.color. |
| value (required) | object | UID of the term to match, together with its ancestors. |
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- Throws NullReferenceException if key or value is null, because the condition needs both a field path and a term.
- Throws TaxonomyException if the instance already holds a condition on key, because each field path holds one condition. Use the inherited Or or And method to combine two conditions on one field.
- There is no other client-side validation. EqualAndAbove stores an empty key or an unknown term UID as given.
- An invalid value surfaces as a ContentstackException (or a subclass) when Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. EqualAndAbove stores the condition { "$eq_above": value } under key and makes no request.
- The match includes the named term. Use the Above method to match the ancestors only.
- Sends no levels value, so the API matches ancestors up to 10 levels above the term (Equal and Above Operator). The Hierarchy levels note on the Taxonomy class page gives the Where workaround that sets the levels.
- Chaining EqualAndAbove makes the following Find call GET /taxonomies/entries, so Find returns entries instead of taxonomies.
Example
Basic usage: match a term and its ancestors
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<Entry> result = await client.Taxonomies()
.EqualAndAbove("taxonomies.<TAXONOMY_UID>", "<TERM_UID>")
.Find<Entry>();
foreach (Entry entry in result)
{
Console.WriteLine(entry.Title);
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}EqualAndBelow
EqualAndBelow matches entries tagged with a term or any of its descendants.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Taxonomy field path, for example taxonomies.color. |
| value (required) | object | UID of the term to match, together with its descendants. |
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- Throws NullReferenceException if key or value is null, because the condition needs both a field path and a term.
- Throws TaxonomyException if the instance already holds a condition on key, because each field path holds one condition. Use the inherited Or or And method to combine two conditions on one field.
- There is no other client-side validation. EqualAndBelow stores an empty key or an unknown term UID as given.
- An invalid value surfaces as a ContentstackException (or a subclass) when Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. EqualAndBelow stores the condition { "$eq_below": value } under key and makes no request.
- The match includes the named term. Use the Below method to match the descendants only.
- Sends no levels value, so the API matches descendants up to 10 levels below the term (Equal and Below Operator). The Hierarchy levels note on the Taxonomy class page gives the Where workaround that sets the levels.
- Chaining EqualAndBelow makes the following Find call GET /taxonomies/entries, so Find returns entries instead of taxonomies.
Example
Basic usage: match a term and its descendants
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<Entry> result = await client.Taxonomies()
.EqualAndBelow("taxonomies.<TAXONOMY_UID>", "<TERM_UID>")
.Find<Entry>();
foreach (Entry entry in result)
{
Console.WriteLine(entry.Title);
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}Fetch
Fetch reads one published taxonomy by its UID.
Returns: Task<T>. The requested taxonomy.
Validation
- Throws TaxonomyException if the instance holds no taxonomy UID, because Fetch reads one specific taxonomy. Create the instance with client.Taxonomies("<TAXONOMY_UID>").
- Throws TaxonomyException if the request fails, for example for an unknown taxonomy UID.
- Throws TaxonomyException with ErrorCode 0 if the response does not deserialize into T.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Calls GET /taxonomies/{taxonomy_uid} (Get a single taxonomy) and makes one HTTP request per call.
- Deserializes the taxonomy object of the response into T and returns it. When the response has no taxonomy key, the SDK deserializes the whole response body into T.
- Sends the values from SetLocale, IncludeFallback and AddParam. The inherited Query methods, for example IncludeBranch, do not reach this request.
- With a locale and no fallback, the API returns a 404 error for a taxonomy that has no localization in that locale. Chain IncludeFallback to receive the taxonomy through the locale fallback hierarchy of the branch.
- Does not return the terms of the taxonomy. Use the Terms method to list them.
Example
Basic usage: read a taxonomy into a model class
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
TaxonomyInfo taxonomy = await client.Taxonomies("<TAXONOMY_UID>").Fetch<TaxonomyInfo>();
Console.WriteLine($"{taxonomy.Name}: {taxonomy.Description}");
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}
public class TaxonomyInfo
{
public string Uid { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}Localized: read a taxonomy in a locale, with fallback
using System;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
JsonObject taxonomy = await client.Taxonomies("<TAXONOMY_UID>")
.SetLocale("<LOCALE>")
.IncludeFallback()
.Fetch<JsonObject>();
Console.WriteLine($"{taxonomy["name"]} ({taxonomy["locale"]})");
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Find
Find lists the taxonomies published to the environment, or returns the entries that match the filters chained before it.
Returns: Task<ContentstackCollection<T>>. The published taxonomies, or the entries that match the filters.
Validation
- Throws TaxonomyException if the instance holds a taxonomy UID, because Find works across all taxonomies. Create the instance with client.Taxonomies() instead. The check applies even when you chain a filter first.
- When you list taxonomies, Find throws TaxonomyException if the request fails or if the response does not deserialize into T.
- When you filter entries, Find throws QueryFilterException if the request fails, because the entry filter runs through the inherited Query pipeline.
- Both exceptions inherit from ContentstackException. Catch ContentstackException to handle either path.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Find selects one of the two endpoints below from what you chain before it:
- With no filter, it calls GET /taxonomies (Get all taxonomies) and reads the items from the taxonomies array of the response.
- After any filter, it calls GET /taxonomies/entries (Get all entries with defined taxonomies) and reads the items from the entries array. A filter is one of the four hierarchy filters on this class, or an inherited filter such as Exists or Where.
- Makes one HTTP request per call.
- The two paths read different query parameters:
- The taxonomy list sends the values from SetLocale, IncludeFallback and AddParam.
- The entry filter sends the values from the inherited Query methods, for example Limit, Skip and IncludeCount. The Known issue notes on the Taxonomy class page cover the gaps between the two.
- Does not page through results. Each call returns the one page of results that the API sends back.
- To page the taxonomy list, send skip and limit through AddParam.
- To page the entry filter, call the inherited Skip and Limit methods.
- Count on the result holds a total only when the response carries count. Skip and Limit on the result stay 0.
Example
Basic usage: list the published taxonomies
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<TaxonomyInfo> result = await client.Taxonomies().Find<TaxonomyInfo>();
foreach (TaxonomyInfo taxonomy in result)
{
Console.WriteLine($"{taxonomy.Uid}: {taxonomy.Name}");
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}
public class TaxonomyInfo
{
public string Uid { get; set; }
public string Name { get; set; }
}Pagination: page through the taxonomy list
using System;
using System.Linq;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// The taxonomy list reads skip and limit only through AddParam
ContentstackCollection<JsonObject> page = await client.Taxonomies()
.AddParam("skip", "10")
.AddParam("limit", "10")
.Find<JsonObject>();
Console.WriteLine($"This page holds {page.Items.Count()} taxonomies");
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Filter entries: find entries by term, 10 at a time
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Taxonomy taxonomy = client.Taxonomies().EqualAndBelow("taxonomies.<TAXONOMY_UID>", "<TERM_UID>");
// The entry filter reads the inherited Query methods
taxonomy.Skip(0);
taxonomy.Limit(10);
ContentstackCollection<Entry> result = await taxonomy.Find<Entry>();
foreach (Entry entry in result)
{
Console.WriteLine(entry.Title);
}
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Edge case: filter entries in a locale
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
// Taxonomy.SetLocale does not reach the entry filter, so call Query.SetLocale through a Query variable
Query query = client.Taxonomies().Below("taxonomies.<TAXONOMY_UID>", "<TERM_UID>");
query.SetLocale("<LOCALE>");
ContentstackCollection<Entry> result = await query.Find<Entry>();
foreach (Entry entry in result)
{
Console.WriteLine(entry.Title);
}
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}IncludeFallback
IncludeFallback returns taxonomies through the locale fallback hierarchy of the branch when they have no localization in the requested locale.
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- There is no client-side validation.
- An invalid value surfaces as a ContentstackException (or a subclass) when Fetch or Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. IncludeFallback stores include_fallback=true and makes no request. No method removes it, so build a new instance to send a request without it.
- Fetch and the taxonomy list from Find send the value.
- The API applies it in two ways:
- On Fetch, a taxonomy with no localization in the requested locale returns through the fallback hierarchy instead of a 404 error (Get a single taxonomy).
- On the taxonomy list, the response also includes the taxonomies that have no localization in the requested locale. Each taxonomy's locale field shows the locale it came from (Get all taxonomies).
- Works with or without SetLocale.
- To use the fallback hierarchy of a branch other than main, set Branch on ContentstackOptions, so the SDK sends the branch header.
- Replaces the Query method of the same name. The entry filter does not send this value. The Known issue notes on the Taxonomy class page give the workaround for the entry filter.
Example
Basic usage: read a taxonomy with locale fallback
using System;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
JsonObject taxonomy = await client.Taxonomies("<TAXONOMY_UID>")
.SetLocale("<LOCALE>")
.IncludeFallback()
.Fetch<JsonObject>();
Console.WriteLine($"{taxonomy["name"]} ({taxonomy["locale"]})");
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}SetLocale
SetLocale sets the locale that Fetch and the taxonomy list request the taxonomy names in.
| Name | Type | Description |
|---|---|---|
| locale (required) | string | Locale code, for example fr-fr. |
Returns: Taxonomy. The same taxonomy, for chaining.
Validation
- There is no client-side validation of the locale code.
- A null or empty locale changes nothing. SetLocale keeps any locale set earlier and does not throw.
- An invalid value surfaces as a ContentstackException (or a subclass) when Fetch or Find sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. SetLocale stores the locale query parameter and makes no request. A second call replaces the first value.
- Fetch and the taxonomy list from Find send the value (Get a single taxonomy, Get all taxonomies).
- Without IncludeFallback, the API returns only the values localized in this locale. Fetch returns a 404 error for a taxonomy with no localization in it.
- Replaces the Query method of the same name. The entry filter does not send this value. The Known issue notes on the Taxonomy class page give the workaround for the entry filter.
- Does not reach the terms. The Term and Terms methods create objects with their own SetLocale.
Example
Basic usage: read a taxonomy in a locale
using System;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
JsonObject taxonomy = await client.Taxonomies("<TAXONOMY_UID>")
.SetLocale("<LOCALE>")
.Fetch<JsonObject>();
Console.WriteLine(taxonomy["name"]);
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}List taxonomies: request localized names
using System;
using System.Text.Json.Nodes;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
ContentstackCollection<JsonObject> result = await client.Taxonomies()
.SetLocale("<LOCALE>")
.Find<JsonObject>();
foreach (JsonObject taxonomy in result)
{
Console.WriteLine(taxonomy["name"]);
}
}
catch (ContentstackException e)
{
Console.WriteLine(e.Message);
}Term
Term creates a Term object for one term of this taxonomy.
| Name | Type | Description |
|---|---|---|
| termUid (required) | string | UID of the term to work with. |
Returns: Term. A new term object.
Validation
- Throws TaxonomyException if the instance holds no taxonomy UID, because a term belongs to one specific taxonomy. Create the instance with client.Taxonomies("<TAXONOMY_UID>").
- Throws TaxonomyException if termUid is null or empty, because the term needs a UID for its request path.
- There is no other client-side validation. An unknown term UID surfaces as a TaxonomyException when a request method on the Term sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Term makes no request. Call Fetch, Locales, Ancestors or Descendants on the returned object to send one.
- Passes only the client, the taxonomy UID and termUid to the new object. Values from SetLocale, IncludeFallback and AddParam on the taxonomy do not reach the term. Set them on the Term itself.
- Each call returns a new Term with no query parameters.
Example
Basic usage: read one term of a taxonomy
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
Term term = client.Taxonomies("<TAXONOMY_UID>").Term("<TERM_UID>");
TermInfo result = await term.SetLocale("<LOCALE>").Fetch<TermInfo>();
Console.WriteLine($"{result.Uid}: {result.Name}");
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}
public class TermInfo
{
public string Uid { get; set; }
public string Name { get; set; }
}Terms
Terms creates a TermQuery object that lists the published terms of this taxonomy.
Returns: TermQuery. A new term query object.
Validation
- Throws TaxonomyException if the instance holds no taxonomy UID, because the terms belong to one specific taxonomy. Create the instance with client.Taxonomies("<TAXONOMY_UID>").
- There is no other client-side validation. An unknown taxonomy UID surfaces as a TaxonomyException when Find on the TermQuery sends the request.
Additional Resource Refer to Content Delivery API Errors for the full error code list.
Behavior
- Client-side only. Terms makes no request. Call Find on the returned object to send one.
- Passes only the client and the taxonomy UID to the new object. Values from SetLocale, IncludeFallback and AddParam on the taxonomy do not reach the term query. Set them on the TermQuery itself.
- Each call returns a new TermQuery with no query parameters.
Example
Basic usage: list the terms of a taxonomy
using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");
try
{
TermQuery terms = client.Taxonomies("<TAXONOMY_UID>").Terms();
ContentstackCollection<TermInfo> result = await terms.Limit(20).Find<TermInfo>();
foreach (TermInfo term in result)
{
Console.WriteLine($"{term.Uid}: {term.Name}");
}
}
catch (ContentstackException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}
public class TermInfo
{
public string Uid { get; set; }
public string Name { get; set; }
}