Query

View as Markdown

Query

A query narrows the entries of one content type to those that match the conditions you set. Use this class to do the following:

  • match field values with comparisons, value lists, patterns, and existence checks
  • filter entries by the entries their reference fields point to
  • combine conditions with $and and $or
  • choose the locale, variants, referenced content, and fields the response contains
  • sort, page, and send the request

Get a Query from client.ContentType("<CONTENT_TYPE_UID>").Query(). Every method below works on that query. The Taxonomy class inherits these methods to filter entries across content types. See the Taxonomy class page.

NameTypeDescription
ContentTypeId string

Read and write. UID of the content type the query reads entries from.

Stack ContentstackClient

Read. The SDK does not set this property, so it reads null.

AddParam

AddParam adds a URL query parameter that has no dedicated method.

NameTypeDescription
key (required)string

Name of the query parameter.

Default: Not applicable
value (required)string

Value of the query parameter.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key is null, because the SDK stores each parameter under its name.
  • Throws QueryFilterException if the query already holds a parameter named key, for example from an earlier AddParam or Limit call, because the SDK stores each parameter once. See Options set once per query on the Query class page.
  • A null value is not an error. The SDK sends the parameter with an empty value.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. AddParam stores key and value as a URL query parameter and makes no request. Find, FindOne and Count send <key>=<value>.
  • AddParam writes a URL query parameter, not a condition in the query parameter. To add a condition, use the Where method.
  • The SDK does not URL-encode value, so a value that holds & or # changes the request URL. See Request URL encoding in the SDK-Wide Notes of the usage guide.
  • For example, include_taxonomy_terms=true resolves the taxonomy term names in each entry. See Get all entries in the Content Delivery API reference.

Example

Basic usage: resolve taxonomy terms

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .AddParam("include_taxonomy_terms", "true")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("taxonomies"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Several parameters: expand all references two levels deep

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .AddParam("include_all", "true")
        .AddParam("include_all_depth", "2")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

AddQuery

AddQuery adds an equality condition with a string value to the query conditions.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)string

String value the field must equal.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. AddQuery stores { "<key>": "<value>" } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • AddQuery stores the same condition as the Where method with a string value. Use Where for numbers, booleans and operator objects.
  • AddQuery writes to the query parameter only. To add a separate URL query parameter, use the AddParam method.
  • The API returns the entries whose field value matches value. See Equals Operator in the Content Delivery API reference.

Example

Basic usage: match an exact title

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .AddQuery("title", "Home")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

And

And matches entries that satisfy every condition in a list of sub-queries.

NameTypeDescription
queryObjects (required)List<Query>

Sub-queries whose conditions the API combines.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if queryObjects is null or empty, because there is nothing to combine.
  • Throws QueryFilterException if the list holds a null item, because the SDK reads the conditions of each item.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. And stores { "$and": [ <conditions of each sub-query> ] } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • A second And call replaces the first list. It does not throw.
  • The SDK reads only the conditions of each sub-query. Their content type, locale, limit and other parameters have no effect.
  • The SDK keeps a reference to each sub-query's conditions, not a copy. A condition you add to a sub-query before Find also reaches the request.
  • Conditions on the main query outside the list still apply, so an entry must also satisfy them.
  • The API returns the entries that satisfy all the sub-query conditions. See AND Operator in the Content Delivery API reference.
  • To match entries that satisfy any one sub-query, use the Or method.

Example

Range: bound one field on both sides

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using System.Collections.Generic;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    // Each sub-query holds one condition on the same field
    Query fromQuery = client.ContentType("<CONTENT_TYPE_UID>").Query().GreaterThanOrEqualTo("price", 100);
    Query toQuery = client.ContentType("<CONTENT_TYPE_UID>").Query().LessThan("price", 500);

    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .And(new List<Query> { fromQuery, toQuery })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Ascending

Ascending sorts the entries by a field in ascending order.

NameTypeDescription
key (required)string

UID of the field to sort by.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key is null, because the sort needs a field.
  • Throws QueryFilterException on a second call on the same query, because the SDK stores the asc parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Ascending sets the asc URL query parameter and makes no request. Find, FindOne and Count send asc=<key>.
  • The API sorts the entries in ascending order of the field value. See Order by asc in the Content Delivery API reference.
  • Ascending and the Descending method write different parameters, so a query can hold both.

Example

Basic usage: sort by a field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Ascending("updated_at")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

AssetFields

AssetFields requests extra field groups for the assets in each entry.

NameTypeDescription
fields (required)params string[]

Asset field groups to include.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Calling it with no arguments, null, or an empty array is not an error. AssetFields adds nothing.
  • Throws ArgumentException on a second call with arguments, because the SDK stores the asset_fields[] parameter once. Pass every group in one call.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. AssetFields sets the asset_fields[] URL query parameter and makes no request. Find, FindOne and Count send one asset_fields[]=<group> pair per argument.
  • fields is a params array, so you can pass the groups as separate arguments or as one array.
  • With visual_markups, the API returns the hotspot and bounding-box annotations of each embedded asset under the visual_markups key. See Get all entries in the Content Delivery API reference.

Example

Basic usage: request visual markups for assets

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .AssetFields("visual_markups")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

ContainedIn

ContainedIn matches entries whose field value equals one of the given values.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
values (required)object[]

Values the field may equal.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or values is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • ContainedIn does not check the array length. The SDK sends an empty array as given.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. ContainedIn copies values into a list, stores { "<key>": { "$in": [ <values> ] } } in the query conditions, and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes each value with System.Text.Json, so numbers and strings keep their JSON types.
  • The API returns the entries whose field value matches any of values. See Array Equals Operator in the Content Delivery API reference.
  • To exclude a list of values, use the NotContainedIn method.

Example

Basic usage: match a list of strings

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .ContainedIn("color", new object[] { "Gold", "Black" })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Number field: match a list of prices

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .ContainedIn("price", new object[] { 101, 749 })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

Count

Count sends the query and returns the number of matching entries, without the entries.

Returns: Task<JsonObject>. The response body as a JSON object.

Validation

  • Throws QueryFilterException on a second Count call on the same query, because the SDK stores the count parameter once. Build a new query for each count.
  • Count throws QueryFilterException, a subclass of ContentstackException, when the API rejects the request. StatusCode, ErrorCode, Message and Errors carry the API's error details.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Count sets the count=true URL query parameter, then sends the same request as the Find method with every condition the query holds.
  • With count=true, the API returns only the number of matching entries. See Count in the Content Delivery API reference.
  • Count returns the raw response body as a JsonObject from System.Text.Json.Nodes, not a typed value.
  • Known issue: count=true stays on the query, so a later Find on the same query does not return the entries. Build a separate query for Find.
  • To get the entries and the total in one request, use the IncludeCount method with Find.

Example

Basic usage: count matching entries

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using System.Text.Json.Nodes;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    JsonObject result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Exists("url")
        .Count();
    Console.WriteLine(result.ToJsonString());
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Descending

Descending sorts the entries by a field in descending order.

NameTypeDescription
key (required)string

UID of the field to sort by.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key is null, because the sort needs a field.
  • Throws QueryFilterException on a second call on the same query, because the SDK stores the desc parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Descending sets the desc URL query parameter and makes no request. Find, FindOne and Count send desc=<key>.
  • The API sorts the entries in descending order of the field value. See Order by desc in the Content Delivery API reference.
  • Descending and the Ascending method write different parameters, so a query can hold both.

Example

Basic usage: sort by a field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Descending("updated_at")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Except

Except leaves the listed top-level fields out of each entry.

NameTypeDescription
fieldUids (required)string[]

Field UIDs to leave out.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • A null or empty array is not an error. Except adds nothing.
  • A second call on the same query is not an error. The SDK keeps the first list and ignores the second, without a warning. Pass every field in one call.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Except sets the except[BASE][] URL query parameter and makes no request. Find, FindOne and Count send one pair per field.
  • BASE refers to the top-level fields of the entry. The API returns every field of each entry except the listed ones. See Exclude Operator in the Content Delivery API reference.
  • To shape the fields of a referenced entry, use the IncludeExceptReference method.

Example

Basic usage: leave out two fields

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Except(new string[] { "body", "seo" })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Exists

Exists matches entries that have a value for the given field.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key is null, because the condition needs a field.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Exists stores { "<key>": { "$exists": true } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The API returns the entries in which the field exists. See Exists in the Content Delivery API reference.
  • To match entries that lack the field, use the NotExists method.

Example

Basic usage: check a field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Exists("url")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Field inside a group: check a subfield

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Exists("seo.meta_title")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

Find

Find sends the query and returns the matching entries of the content type.

Returns: Task<ContentstackCollection<T>>. The matching entries.

Validation

  • Find throws QueryFilterException, a subclass of ContentstackException, when the API rejects the request. StatusCode, ErrorCode, Message and Errors carry the API's error details.
  • For a network failure with no HTTP response, such as a timeout, the same exception carries StatusCode InternalServerError (500) and ErrorCode 0. Read Message and InnerException for the cause.
  • Find throws ContentstackException if the entries in the response do not bind to T. The InnerException holds the JsonException.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Find sends one GET /content_types/{content_type_uid}/entries request with the client's environment, the query conditions as the query parameter, and every URL query parameter and header that the query holds.
  • Find returns one page. Without the Limit method, the API returns the first 100 entries. See Pagination in the Content Delivery API reference.
  • The returned ContentstackCollection<T> holds the entries in Items and is enumerable. Count holds the total number of matches only after the IncludeCount method. Skip and Limit on the collection read 0. See the ContentstackCollection class page.
  • With T set to your own class, the SDK binds JSON field names to properties without regard to case, so title fills Title.
  • Find does not change the query, so you can call it again to send the same request.

Example

Basic usage: find entries

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Where("title", "Home")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine($"{entry.Uid} {entry.Title}");
    }
}
catch (ContentstackException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Model class: bind entries to your own type

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    ContentstackCollection<Product> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Limit(10)
        .Find<Product>();
    foreach (Product product in result)
    {
        Console.WriteLine($"{product.Title} {product.Url}");
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

public class Product
{
    public string Uid { get; set; }
    public string Title { get; set; }
    public string Url { get; set; }
}

FindOne

FindOne sends the query with a limit of one and returns the first matching entry.

Returns: Task<ContentstackCollection<T>>. A collection holding at most one matching entry.

Validation

  • FindOne throws QueryFilterException, a subclass of ContentstackException, when the API rejects the request. StatusCode, ErrorCode, Message and Errors carry the API's error details.
  • FindOne throws ContentstackException if the entry in the response does not bind to T.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • FindOne sets the limit URL query parameter to 1, replacing any value from the Limit method, then sends the same request as the Find method.
  • The change to limit stays on the query. A later Find on the same query also returns at most one entry.
  • FindOne returns a collection, not a single entry. Read the entry from Items. An empty collection means no entry matched.
  • The Skip, Ascending and Descending methods decide which entry comes first.

Example

Basic usage: get the newest matching entry

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using System.Linq;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Descending("updated_at")
        .FindOne<Entry>();
    Entry entry = result.Items.FirstOrDefault();
    Console.WriteLine(entry == null ? "No match" : entry.Title);
}
catch (ContentstackException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

GreaterThan

GreaterThan matches entries whose field value is greater than the given value.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)object

Lower bound the field value must exceed.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • GreaterThan does not check that value suits the field type.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. GreaterThan stores { "<key>": { "$gt": <value> } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes value with System.Text.Json, so a number goes as a JSON number and a string as a JSON string.
  • The API returns the entries whose field value is greater than value, not equal to it. See Greater Than in the Content Delivery API reference.
  • On a date field such as updated_at, pass the date as an ISO 8601 string, for example "2026-01-01".
  • To bound one field on both sides, build each condition in its own query and combine them with the And method.

Example

Basic usage: compare a number field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .GreaterThan("price", 100)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Date field: match entries updated after a date

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .GreaterThan("updated_at", "2026-01-01")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

GreaterThanOrEqualTo

GreaterThanOrEqualTo matches entries whose field value is greater than or equal to the given value.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)object

Lower bound the field value must reach.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • GreaterThanOrEqualTo does not check that value suits the field type.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. GreaterThanOrEqualTo stores { "<key>": { "$gte": <value> } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes value with System.Text.Json, so a number goes as a JSON number and a string as a JSON string.
  • The API returns the entries whose field value is greater than or equal to value. See Greater Than Or Equal To in the Content Delivery API reference.
  • On a date field such as updated_at, pass the date as an ISO 8601 string, for example "2026-01-01".
  • To bound one field on both sides, build each condition in its own query and combine them with the And method.

Example

Basic usage: compare a number field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .GreaterThanOrEqualTo("price", 100)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Date field: match entries updated on or after a date

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .GreaterThanOrEqualTo("updated_at", "2026-01-01")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

IncludeBranch

IncludeBranch adds the branch of each entry to the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_branch parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeBranch sets the include_branch URL query parameter and makes no request. Find, FindOne and Count send include_branch=true.
  • The API adds the _branch top-level key, which states the unique ID of the branch the entry belongs to. See Get all entries in the Content Delivery API reference.
  • IncludeBranch does not choose the branch. Set Branch on the client options, or pass branch to the Variant method.

Example

Basic usage: include the branch key

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeBranch()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("_branch"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

IncludeCount

IncludeCount adds the total number of matching entries to the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_count parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeCount sets the include_count URL query parameter and makes no request. Find, FindOne and Count send include_count=true.
  • The API adds the total number of matching entries, not only those on the current page, as count. See Count in the Content Delivery API reference.
  • Find and FindOne read count into the Count property of the returned collection. Without IncludeCount, Count reads 0.
  • To get only the number, without the entries, use the Count method.

Example

Basic usage: read the total number of matches

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Limit(10)
        .IncludeCount()
        .Find<Entry>();
    // Count holds the total number of matches, not the page size
    Console.WriteLine($"Total matches: {result.Count}");
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

IncludeExceptReference

IncludeExceptReference expands a reference field and leaves out the listed fields of each referenced entry.

NameTypeDescription
keys (required)string[]

Field UIDs of the referenced entry to leave out.

Default: Not applicable
referenceKey (required)string

UID of the reference field to expand.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • A null or empty keys array is not an error. IncludeExceptReference adds nothing.
  • A second call with the same referenceKey is not an error. The SDK keeps the first list and ignores the second.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeExceptReference makes no request. It sets two URL query parameters:
    • include[]=<referenceKey>, only when the query has no reference list yet.
    • except[<referenceKey>][], one pair per item in keys.
  • Known issue: When the query already has a reference list, IncludeExceptReference does not add referenceKey to it, so the API returns that reference field as UIDs. Pass every reference field to one IncludeReference call with an array before you call IncludeExceptReference.
  • Call IncludeReference before IncludeExceptReference, not after. IncludeReference throws ArgumentException when a reference list exists.
  • The API returns every field of each referenced entry except the listed ones. See Exclude Operator in the Content Delivery API reference.

Example

Basic usage: shape one reference field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeExceptReference(new string[] { "title", "email" }, "author")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("author"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Several reference fields: list them in IncludeReference first

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeReference(new string[] { "author", "category" })
        .IncludeExceptReference(new string[] { "title", "email" }, "author")
        .IncludeExceptReference(new string[] { "title" }, "category")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("category"));
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

IncludeFallback

IncludeFallback returns content from the fallback locale for entries not published in the requested locale.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_fallback parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeFallback sets the include_fallback URL query parameter and makes no request. Find, FindOne and Count send include_fallback=true.
  • The API includes the published content from the fallback locale when the requested locale has no published content. See Get all entries in the Content Delivery API reference.
  • Pair it with the SetLocale method to name the requested locale.

Example

Basic usage: fall back for 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
{
    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .SetLocale("<LOCALE>")
        .IncludeFallback()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

IncludeMetadata

IncludeMetadata adds the metadata of each entry to the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_metadata parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeMetadata sets the include_metadata URL query parameter and makes no request. Find, FindOne and Count send include_metadata=true.
  • The API adds each entry's extension metadata under the _metadata key. See Get all entries in the Content Delivery API reference.

Example

Basic usage: include entry metadata

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeMetadata()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("_metadata"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

IncludeOnlyReference

IncludeOnlyReference expands a reference field and returns only the listed fields of each referenced entry.

NameTypeDescription
keys (required)string[]

Field UIDs of the referenced entry to return.

Default: Not applicable
referenceKey (required)string

UID of the reference field to expand.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • A null or empty keys array is not an error. IncludeOnlyReference adds nothing.
  • A second call with the same referenceKey is not an error. The SDK keeps the first list and ignores the second.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeOnlyReference makes no request. It sets two URL query parameters:
    • include[]=<referenceKey>, only when the query has no reference list yet.
    • only[<referenceKey>][], one pair per item in keys.
  • Known issue: When the query already has a reference list, IncludeOnlyReference does not add referenceKey to it, so the API returns that reference field as UIDs. Pass every reference field to one IncludeReference call with an array before you call IncludeOnlyReference.
  • Call IncludeReference before IncludeOnlyReference, not after. IncludeReference throws ArgumentException when a reference list exists.
  • The API returns only the listed fields of each referenced entry. See Only Operator in the Content Delivery API reference.

Example

Basic usage: shape one reference field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeOnlyReference(new string[] { "title", "email" }, "author")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("author"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Several reference fields: list them in IncludeReference first

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeReference(new string[] { "author", "category" })
        .IncludeOnlyReference(new string[] { "title", "email" }, "author")
        .IncludeOnlyReference(new string[] { "title" }, "category")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("category"));
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

IncludeOwner

IncludeOwner requests the owner details of each entry in the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_owner parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeOwner sets the include_owner URL query parameter and makes no request. Find, FindOne and Count send include_owner=True.

Example

Basic usage: include owner details

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeOwner()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("_owner"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

IncludeReference

IncludeReference returns the content of referenced entries in place of their UIDs.

NameTypeDescription
filed_uid (required)string

UID of the reference field to expand.

Default: Not applicable
filed_uids (required)string[]

UIDs of the reference fields to expand.

Default: Not applicable

Returns: Query. The same query, for chaining.

Overloads

  • IncludeReference(string filed_uid)
  • IncludeReference(string[] filed_uids)

Validation

  • A null or empty argument is not an error. IncludeReference adds nothing.
  • Throws ArgumentException if the query already has a reference list, from an earlier IncludeReference, IncludeOnlyReference or IncludeExceptReference call, because the SDK stores the include[] parameter once. Pass every reference field in one call with the array overload.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeReference sets the include[] URL query parameter and makes no request. Find, FindOne and Count send one include[]=<field UID> pair per field.
  • The parameter names keep the SDK's spelling, filed_uid and filed_uids, for named arguments.
  • Without include[], the API returns only the UIDs of referenced entries. With it, the API returns their content. See Include Reference in the Content Delivery API reference.
  • To limit the fields of a referenced entry, use the IncludeOnlyReference or IncludeExceptReference method after IncludeReference.
  • To add the content type UID to each referenced entry, chain the IncludeReferenceContentTypeUID method.

Example

Basic usage: expand one reference field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeReference("author")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("author"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Array overload: expand several reference fields

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeReference(new string[] { "author", "category" })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("category"));
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

IncludeReferenceContentTypeUID

IncludeReferenceContentTypeUID adds the content type UID to each referenced entry in the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_reference_content_type_uid parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeReferenceContentTypeUID sets the include_reference_content_type_uid URL query parameter and makes no request. Find, FindOne and Count send include_reference_content_type_uid=True.
  • It affects only reference fields that the response expands. Pair it with the IncludeReference method.

Example

Basic usage: include content type UIDs of references

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeReference("author")
        .IncludeReferenceContentTypeUID()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("author"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

IncludeSchema

IncludeSchema requests the content type schema, with its global field schemas, in the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_schema and include_global_field_schema parameters once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. IncludeSchema sets two URL query parameters and makes no request. Find, FindOne and Count send include_schema=True and include_global_field_schema=True.
  • Known issue: Find and FindOne return only the entries and the count, so the schema in the response does not reach your code. Call Fetch on client.ContentType("<CONTENT_TYPE_UID>") to read the schema. See the ContentType class page.

Example

Basic usage: request the schema with the entries

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .IncludeSchema()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

LessThan

LessThan matches entries whose field value is less than the given value.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)object

Upper bound the field value must stay below.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • LessThan does not check that value suits the field type.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. LessThan stores { "<key>": { "$lt": <value> } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes value with System.Text.Json, so a number goes as a JSON number and a string as a JSON string.
  • The API returns the entries whose field value is less than value, not equal to it. See Less Than in the Content Delivery API reference.
  • On a date field such as updated_at, pass the date as an ISO 8601 string, for example "2026-01-01".
  • To bound one field on both sides, build each condition in its own query and combine them with the And method.

Example

Basic usage: compare a number field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .LessThan("price", 100)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Date field: match entries updated before a date

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .LessThan("updated_at", "2026-01-01")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

LessThanOrEqualTo

LessThanOrEqualTo matches entries whose field value is less than or equal to the given value.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)object

Upper bound the field value must not exceed.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • LessThanOrEqualTo does not check that value suits the field type.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. LessThanOrEqualTo stores { "<key>": { "$lte": <value> } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes value with System.Text.Json, so a number goes as a JSON number and a string as a JSON string.
  • The API returns the entries whose field value is less than or equal to value. See Less Than Or Equal To in the Content Delivery API reference.
  • On a date field such as updated_at, pass the date as an ISO 8601 string, for example "2026-01-01".
  • To bound one field on both sides, build each condition in its own query and combine them with the And method.

Example

Basic usage: compare a number field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .LessThanOrEqualTo("price", 100)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Date field: match entries updated on or before a date

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .LessThanOrEqualTo("updated_at", "2026-01-01")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

Limit

Limit caps the number of entries the response contains.

NameTypeDescription
number (required)int

Maximum number of entries to return.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the limit parameter once. See Options set once per query on the Query class page.
  • Limit does not check the value. The SDK sends zero or a negative number as given.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Limit sets the limit URL query parameter and makes no request. Find and Count send it.
  • Without Limit, the API returns the first 100 entries. See Pagination in the Content Delivery API reference.
  • The API accepts positive integers only. For 0, an empty value, or a non-numeric value, it returns the default number of entries, not every match. See Limit in the Content Delivery API reference.
  • The FindOne method replaces this value with 1.

Example

Basic usage: return at most ten entries

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Limit(10)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

NotContainedIn

NotContainedIn matches entries whose field value equals none of the given values.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
values (required)object[]

Values the field must not equal.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or values is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • NotContainedIn does not check the array length. The SDK sends an empty array as given.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. NotContainedIn copies values into a list, stores { "<key>": { "$nin": [ <values> ] } } in the query conditions, and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes each value with System.Text.Json, so numbers and strings keep their JSON types.
  • The API returns the entries whose field value matches none of values. See Array Not-equals Operator in the Content Delivery API reference.
  • To match a list of values, use the ContainedIn method.

Example

Basic usage: match a list of strings

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .NotContainedIn("color", new object[] { "Gold", "Black" })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Number field: match a list of prices

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .NotContainedIn("price", new object[] { 101, 749 })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

NotEqualTo

NotEqualTo matches entries whose field value does not equal the given value.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)object

Value the field must differ from.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • NotEqualTo does not check that value suits the field type.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. NotEqualTo stores { "<key>": { "$ne": <value> } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes value with System.Text.Json, so a number goes as a JSON number and a string as a JSON string.
  • The API returns the entries whose field value does not match value. See Not-equals Operator in the Content Delivery API reference.
  • To exclude several values at once, use the NotContainedIn method.

Example

Basic usage: exclude one title

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .NotEqualTo("title", "Home")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Number field: exclude one price

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .NotEqualTo("price", 146)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

NotExists

NotExists matches entries that have no value for the given field.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key is null, because the condition needs a field.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. NotExists stores { "<key>": { "$exists": false } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The API returns the entries in which the field does not exist. See Exists in the Content Delivery API reference.
  • To match entries that have the field, use the Exists method.

Example

Basic usage: check a field

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .NotExists("url")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Field inside a group: check a subfield

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .NotExists("seo.meta_title")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

Only

Only returns only the listed top-level fields of each entry.

NameTypeDescription
fieldUid (required)string[]

Field UIDs to return.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • A null or empty array is not an error. Only adds nothing.
  • A second call on the same query is not an error. The SDK keeps the first list and ignores the second, without a warning. Pass every field in one call.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Only sets the only[BASE][] URL query parameter and makes no request. Find, FindOne and Count send one pair per field.
  • BASE refers to the top-level fields of the entry. The API returns only the listed fields of each entry and leaves out the rest. See Only Operator in the Content Delivery API reference.
  • To shape the fields of a referenced entry, use the IncludeOnlyReference method.

Example

Basic usage: return two fields

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Only(new string[] { "title", "url" })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Or

Or matches entries that satisfy at least one condition in a list of sub-queries.

NameTypeDescription
queryObjects (required)List<Query>

Sub-queries whose conditions the API combines.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if queryObjects is null or empty, because there is nothing to combine.
  • Throws QueryFilterException if the list holds a null item, because the SDK reads the conditions of each item.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Or stores { "$or": [ <conditions of each sub-query> ] } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • A second Or call replaces the first list. It does not throw.
  • The SDK reads only the conditions of each sub-query. Their content type, locale, limit and other parameters have no effect.
  • The SDK keeps a reference to each sub-query's conditions, not a copy. A condition you add to a sub-query before Find also reaches the request.
  • Conditions on the main query outside the list still apply, so an entry must also satisfy them.
  • The API returns the entries that satisfy at least one sub-query. See OR Operator in the Content Delivery API reference.
  • To match entries that satisfy every sub-query, use the And method.

Example

Basic usage: match either of two values

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using System.Collections.Generic;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    Query goldQuery = client.ContentType("<CONTENT_TYPE_UID>").Query().Where("color", "Gold");
    Query blackQuery = client.ContentType("<CONTENT_TYPE_UID>").Query().Where("color", "Black");

    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Or(new List<Query> { goldQuery, blackQuery })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

ReferenceIn

ReferenceIn matches entries whose reference field values point to at least one entry that matches a sub-query.

NameTypeDescription
key (required)string

UID of the reference field to filter.

Default: Not applicable
query (required)Query

Sub-query with conditions on the referenced entries.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or query is null, because the condition needs a reference field and a sub-query.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. ReferenceIn stores { "<key>": { "$in_query": { <sub-query conditions> } } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK reads only the conditions of the sub-query. Its content type, locale, limit and other parameters have no effect.
  • The SDK keeps a reference to the sub-query conditions, not a copy. A condition you add to the sub-query before Find also reaches the request.
  • The API returns the entries whose reference field points to an entry that satisfies the sub-query conditions. See Reference Search Equals in the Content Delivery API reference.
  • When the reference field refers to more than one content type, add a _content_type_uid condition to the sub-query to name the referenced content type.
  • To match entries whose references do not satisfy the sub-query, use the ReferenceNotIn method.

Example

Basic usage: filter by a field of the referenced entry

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    // The SDK uses only the conditions of the sub-query
    Query authorQuery = client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Where("title", "John Doe");

    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .ReferenceIn("author", authorQuery)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

ReferenceNotIn

ReferenceNotIn matches entries whose reference field values do not point to an entry that matches a sub-query.

NameTypeDescription
key (required)string

UID of the reference field to filter.

Default: Not applicable
query (required)Query

Sub-query with conditions on the referenced entries.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or query is null, because the condition needs a reference field and a sub-query.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. ReferenceNotIn stores { "<key>": { "$nin_query": { <sub-query conditions> } } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK reads only the conditions of the sub-query. Its content type, locale, limit and other parameters have no effect.
  • The SDK keeps a reference to the sub-query conditions, not a copy. A condition you add to the sub-query before Find also reaches the request.
  • The API returns the entries whose reference field does not point to an entry that satisfies the sub-query conditions. See Reference Search Not-equals in the Content Delivery API reference.
  • When the reference field refers to more than one content type, add a _content_type_uid condition to the sub-query to name the referenced content type.
  • To match entries whose references satisfy the sub-query, use the ReferenceIn method.

Example

Basic usage: filter by a field of the referenced entry

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    // The SDK uses only the conditions of the sub-query
    Query authorQuery = client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Where("title", "John Doe");

    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .ReferenceNotIn("author", authorQuery)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Regex

Regex matches entries whose field value matches a regular expression.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
regex (required)string

Regular expression the field value must match.

Default: Not applicable
modifiers (required)string

Regex options, sent as $options. null sends none.

Default: Not applicable

Returns: Query. The same query, for chaining.

Overloads

  • Regex(string key, string regex)
  • Regex(string key, string regex, string modifiers)

Validation

  • Throws QueryFilterException if key or regex is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Regex does not check the pattern syntax or the modifiers value. The SDK sends both as given.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Regex stores { "<key>": { "$regex": "<regex>" } } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The three-argument overload adds "$options": "<modifiers>" to the same condition when modifiers is not null.
  • The API returns the entries whose field value matches the pattern. See Search by Regex in the Content Delivery API reference.
  • The SDK does not URL-encode the pattern, so a pattern that holds & or # changes the request URL. See Request URL encoding in the SDK-Wide Notes of the usage guide.

Example

Basic usage: match titles that start with a prefix

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Regex("title", "^Blog")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

All parameters: add a regex option

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Regex("title", "^blog", "i")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

RemoveHeader

RemoveHeader deletes a request header from the query.

NameTypeDescription
key (required)string

Name of the header to remove.

Default: Not applicable

Returns: void. This method returns nothing.

Validation

  • A null or empty key is not an error. RemoveHeader does nothing.
  • A key the query does not hold is not an error. RemoveHeader does nothing.

Behavior

  • Client-side only. RemoveHeader deletes the header from this query and makes no request.
  • It removes headers that the SetHeader and Variant methods add on this query. It does not remove headers set on the client, such as the API key.
  • RemoveHeader returns nothing, so it cannot sit inside a method chain. Call it on the query variable.

Example

Basic usage: replace a header value

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    Query query = client.ContentType("<CONTENT_TYPE_UID>").Query();
    query.SetHeader("x-request-id", "first-value");

    // Remove the header before setting a new value
    query.RemoveHeader("x-request-id");
    query.SetHeader("x-request-id", "second-value");

    ContentstackCollection<Entry> result = await query.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}");
}

RemoveQuery

RemoveQuery deletes the condition stored under the given field UID.

NameTypeDescription
key (required)string

Field UID, or $and or $or, to remove.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key is null, because the SDK looks the key up in the query conditions.
  • A key with no stored condition is not an error. RemoveQuery leaves the query unchanged.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. RemoveQuery deletes the condition from the query conditions and makes no request.
  • It removes conditions that the filter methods store, such as Where, GreaterThan, ContainedIn, ReferenceIn, And and Or.
  • It does not remove URL query parameters such as limit, locale or those from the AddParam method.
  • To replace a condition, call RemoveQuery with the field UID, then add the new condition. A second condition on the same field without RemoveQuery throws QueryFilterException.

Example

Basic usage: replace a condition on the same field

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    Query query = client.ContentType("<CONTENT_TYPE_UID>").Query()
        .GreaterThan("price", 100);

    // Drop the first condition before adding another on the same field
    query.RemoveQuery("price").GreaterThan("price", 500);

    ContentstackCollection<Entry> result = await query.Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

SetCachePolicy

SetCachePolicy records a cache policy on the query.

NameTypeDescription
cachePolicy (required)CachePolicy

Cache policy to record.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • There is no client-side validation.

Behavior

  • SetCachePolicy stores the value and makes no request. Find, FindOne and Count do not read it, so it has no effect on the request.
  • The CachePolicy enum, in the Contentstack.Core.Internals namespace, has one member, NetworkOnly. Every request goes to the API, and the SDK does not cache responses.
  • A second call replaces the first value. It does not throw.

Example

Basic usage: set the network-only policy

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .SetCachePolicy(CachePolicy.NetworkOnly)
        .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}");
}

SetHeader

SetHeader adds a request header to the query.

NameTypeDescription
key (required)string

Name of the header.

Default: Not applicable
value (required)string

Value of the header.

Default: Not applicable

Returns: void. This method returns nothing.

Validation

  • A null or empty key or value is not an error. SetHeader adds nothing.
  • Throws ArgumentException if the query already holds a header named key, because the query stores each header once. Call the RemoveHeader method first to change a value.

Behavior

  • Client-side only. SetHeader stores the header on this query and makes no request. Find, FindOne and Count send it.
  • A header set on the query replaces a client-level header with the same name, for this query's requests only.
  • SetHeader returns nothing, so it cannot sit inside a method chain. Call it on the query variable.

Example

Basic usage: add a custom header

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    Query query = client.ContentType("<CONTENT_TYPE_UID>").Query();
    query.SetHeader("x-request-id", "homepage-build");

    ContentstackCollection<Entry> result = await query.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}");
}

SetLocale

SetLocale sets the locale of the entries the query returns.

NameTypeDescription
Locale (required)string

Locale code, such as en-us.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • There is no client-side validation.
  • A null or empty Locale is not an error. The SDK sends an empty locale parameter.
  • An invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. SetLocale sets the locale URL query parameter and makes no request. Find, FindOne and Count send it.
  • A second call replaces the first value. It does not throw.
  • The API returns only the entries published in this locale. See Get all entries in the Content Delivery API reference.
  • To fall back to another locale for entries not published in this one, chain the IncludeFallback method.

Example

Basic usage: fetch 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
{
    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .SetLocale("<LOCALE>")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Skip

Skip sets the number of matching entries the response skips, for pagination.

NameTypeDescription
number (required)int

Number of entries to skip.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the skip parameter once. See Options set once per query on the Query class page.
  • Skip does not check the value. The SDK sends a negative number as given.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Skip sets the skip URL query parameter and makes no request. Find, FindOne and Count send it.
  • The API skips that number of entries before it returns the next page. See Skip in the Content Delivery API reference.
  • To page through results, pair Skip with the Limit method and build a new query for each page. See Pagination on the Query class page.

Example

Basic usage: read the second page of ten entries

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Skip(10)
        .Limit(10)
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Variant

Variant returns the entries with the content of one or more entry variants applied.

NameTypeDescription
variant_header (required)string

Variant UID or variant alias.

Default: Not applicable
branchstring

Branch to read the variant from.

Default: null
variant_headers (required)List<string>

Variant UIDs or aliases, in priority order.

Default: Not applicable

Returns: Query. The same query, for chaining.

Overloads

  • Variant(string variant_header, string branch = null)
  • Variant(List<string> variant_headers, string branch = null)

Validation

  • A null or empty variant_header, or an empty list, is not an error. The SDK sends no x-cs-variant-uid header, so the API returns the base entries.
  • Throws ArgumentNullException if variant_headers is null, because the SDK joins the list items.
  • Throws ArgumentException on a second Variant call, or after a SetHeader call for x-cs-variant-uid or branch, because the query stores each header once. Call the RemoveHeader method for both headers first.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Variant makes no request. Find, FindOne and Count send the two headers it sets on the query:
    • x-cs-variant-uid, holding the variant UID, or the list joined with commas.
    • branch, holding the branch to read from.
  • When branch is null, empty, or white space, the SDK uses the Branch set on the client options. When the client has no branch, the SDK sends main.
  • The branch header from Variant replaces the client's branch for this query's requests only.
  • The API accepts a variant alias in place of a variant UID. It applies up to five variants by default, and the first one in the list takes priority on the base entry fields. See Get all entry variants in the Content Delivery API reference.

Example

Basic usage: apply one variant

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Variant("<VARIANT_UID>")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

All parameters: apply a list of variants on a branch

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using System.Collections.Generic;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Variant(new List<string> { "<VARIANT_UID>" }, "<BRANCH>")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

One variant on a branch

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Variant("<VARIANT_UID>", "<BRANCH>")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

Where

Where matches entries whose field equals the given value.

NameTypeDescription
key (required)string

UID or dotted path of the field to filter.

Default: Not applicable
value (required)object

Value the field must equal.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException if key or value is null, because the condition needs a field and a value to compare.
  • Throws QueryFilterException if the query already holds a condition on key, because the SDK stores one condition per field. See How conditions combine on the Query class page.
  • Where does not check that value suits the field type.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. Where stores { "<key>": <value> } in the query conditions and makes no request. Find, FindOne and Count send the conditions as the query parameter.
  • The SDK serializes value with System.Text.Json. A string, number or bool goes as that JSON type.
  • A Dictionary<string, object> value goes as a JSON object, so Where can send any operator the API accepts, such as the taxonomy operators that have no dedicated method.
  • The API returns the entries whose field value matches value. See Equals Operator in the Content Delivery API reference.
  • To match a field inside a Group field, pass the dotted path, for example "seo.meta_title".
  • A taxonomy condition takes the path taxonomies.<TAXONOMY_UID> as key and a term UID, or an operator object, as value. See Taxonomy in the Content Delivery API reference.

Example

Basic usage: match an exact title

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Where("title", "Home")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

Taxonomy: match entries tagged with 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.ContentType("<CONTENT_TYPE_UID>").Query()
        .Where("taxonomies.<TAXONOMY_UID>", "<TERM_UID>")
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

Operator object: match a term and the terms below it

using System;
using Contentstack.Core;
using Contentstack.Core.Internals;
using Contentstack.Core.Models;
using System.Collections.Generic;

ContentstackClient client = new ContentstackClient("<API_KEY>", "<DELIVERY_TOKEN>", "<ENVIRONMENT>");

try
{
    ContentstackCollection<Entry> result = await client.ContentType("<CONTENT_TYPE_UID>").Query()
        .Where("taxonomies.<TAXONOMY_UID>", new Dictionary<string, object> { { "$eq_below", "<TERM_UID>" } })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    Console.WriteLine(e.Message);
}

WhereTags

WhereTags filters entries by the tags assigned to them.

NameTypeDescription
tags (required)string[]

Tags to filter entries by.

Default: Not applicable

Returns: Query. The same query, for chaining.

Validation

  • A null or empty tags array is not an error. WhereTags adds nothing.
  • Throws ArgumentException on a second call on the same query, because the SDK stores the tags parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. WhereTags stores the array as the tags URL query parameter and makes no request. Find, FindOne and Count send one tags=<tag> pair per array item.
  • WhereTags writes a URL query parameter, not a condition in the query parameter. The RemoveQuery method does not remove it.
  • Pass every tag in one call.

Example

Basic usage: filter entries by tags

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .WhereTags(new string[] { "featured", "summer" })
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Title);
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}

includeEmbeddedItems

includeEmbeddedItems adds the entries and assets embedded in Rich Text Editor fields to the response.

Returns: Query. The same query, for chaining.

Validation

  • Throws QueryFilterException on a second call on the same query, because the SDK stores the include_embedded_items[] parameter once. See Options set once per query on the Query class page.
  • Any other invalid value surfaces as a QueryFilterException when Find, FindOne or Count sends the request.

Additional Resource Refer to Content Delivery API Errors for the full error code list.

Behavior

  • Client-side only. includeEmbeddedItems sets the include_embedded_items[] URL query parameter and makes no request. Find, FindOne and Count send include_embedded_items[]=BASE.
  • The API includes the first level of entries and assets embedded in Rich Text Editor fields under the _embedded_items key. See Get information on embedded RTE objects in the Content Delivery API reference.
  • The method name starts with a lowercase i. C# names are case-sensitive, so IncludeEmbeddedItems does not compile on a query.

Example

Basic usage: include embedded items

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.ContentType("<CONTENT_TYPE_UID>").Query()
        .includeEmbeddedItems()
        .Find<Entry>();
    foreach (Entry entry in result)
    {
        Console.WriteLine(entry.Get("_embedded_items"));
    }
}
catch (ContentstackException e)
{
    // Thrown when the query is invalid or the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.Message}");
}