Query
Query
A class that defines a query that is used to query for Entry instance.
When Personalize creates a variant in the CMS, it assigns a "Variant Alias" to identify that specific variant. When fetching entry variants using the Delivery API, you can pass variant aliases in place of variant UIDs in thex-cs-variant-uidheader.
AddQuery
Add a custom query against specified key.
| Name | Type | Description |
|---|---|---|
| key | string | field uid. |
| value | string | field value |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().AddQuery("key", "value").Find<Entry>();IncludeCount
Retrieve count and data of objects in result.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeCount().Find<Entry>();IncludeBranch
Include branch for publish content.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeBranch().Find<Entry>();IncludeFallback
Include fallback locale publish content, if specified locale content is not publish.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeFallback().Find<Entry>();IncludeMetadata
The includeMetadata method will add the meta information to the response.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeMetadata().Find<Entry>();includeEmbeddedItems
Include Embedded Objects (Entries and Assets) along with entry/entries details.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().includeEmbeddedItems().Find<Entry>();IncludeOnlyReference
Specifies an array of except keys that would be excluded in the response.
| Name | Type | Description |
|---|---|---|
| keys | string[] | Array of the only reference keys to be included in response. |
| referenceKey | string | Key who has reference to some other class object. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeOnlyReference(new String[]{"name", "description"},"referenceUid").Find<Entry>();IncludeExceptReference
Specifies an array of except keys that would be excluded in the response.
| Name | Type | Description |
|---|---|---|
| keys | string[] | Array of the except reference keys to be excluded in response. |
| referenceKey | string | Key who has reference to some other class object. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeExceptReference(new String[]{"name", "description"},"referenceUid").Find<Entry>();IncludeReference
Add a constraint that requires a particular reference key details.
| Name | Type | Description |
|---|---|---|
| referenceField | String | Key that to be constrained. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_Type_uid").Query().IncludeReference("reference_uid_1").Find<Entry>();IncludeReferenceContentTypeUID
This method also includes the content type UIDs of the referenced entries returned in the response.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeReferenceContentTypeUID().Find<Entry>();IncludeReference
Add a constraint that requires a particular reference key details.
| Name | Type | Description |
|---|---|---|
| referenceFields | string[] | Array key that to be constrained. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().IncludeReference(new String[]{"reference_uid_1", "reference_uid_2"}).Find<Entry>();ReferenceIn
Retrieve entries based reference in query
| Name | Type | Description |
|---|---|---|
| key | string | They key to constraint on |
| query | Query | Query object |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");
Query query = contentTypeObj.Query();
query.Where("email_address","[email protected]");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().ReferenceIn("user", query).Find<Entry>();ReferenceNotIn
Retrieve entries based reference not in query
| Name | Type | Description |
|---|---|---|
| key | string | The key to constraint on |
| query | Query | Query object |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");
Query query = contentTypeObj.Query();
query.Where("email_address","[email protected]");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().ReferenceNotIn("user", query).Find<Entry>();Regex
| Name | Type | Description |
|---|---|---|
| key | string | The key to be constrained. |
| regex | string | The regular expression pattern to match. |
| modifiers | string | Any of the following supported Regular expression modifiers.
|
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_type_uid").Query().Regex("name", "^browser").Find<Entry>();using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_type_uid").Query().Regex("name", "^browser", "i").Find<Entry>();RemoveQuery
| Name | Type | Description |
|---|---|---|
| key | string | Query name to remove. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().RemoveQuery("query_key").Find<Entry>();SetCachePolicy
| Name | Type | Description |
|---|---|---|
| cachePolicy | CachePolicy | CachePolicy instance |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().SetCachePolicy(CachePolicy.NetworkElseCache).Find<Entry>();SetLocale
| Name | Type | Description |
|---|---|---|
| Locale | string | Locale to fetch entry |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().SetLocale("en-us").Find<Entry>();SetHeader
| Name | Type | Description |
|---|---|---|
| key | string | header name. |
| value | string | header value against given header name. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_type_uid").Query().SetHeader("custom_key", "custom_value").Find<Entry>();RemoveHeader
| Name | Type | Description |
|---|---|---|
| key | string | key to be remove from header |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> entry = await stack.ContentType("content_type_uid").Query().RemoveHeader("header_to_remove").Find<Entry>();WhereTags
Include tags with which to search entries.
| Name | Type | Description |
|---|---|---|
| tags (required) | string[] | Array of tags you want to match in the entries |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().WhereTags(new String[] {"tag_1", tag_2}).Find<Entry>();Skip
The number of objects to skip before returning any.
| Name | Type | Description |
|---|---|---|
| number | string | No of objects to skip. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Skip(20).Find<Entry>();Limit
A limit on the number of objects to return.
| Name | Type | Description |
|---|---|---|
| number | string | No of objects to limit. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Limit(20).Find<Entry>();Ascending
Sort the results in ascending order with the given key.
| Name | Type | Description |
|---|---|---|
| fieldUid | string | The key to order by. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Ascending("name").Find<Entry>();Descending
Sort the results in descending order with the given key.
| Name | Type | Description |
|---|---|---|
| fieldUid | string | The key to order by. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Descending("name").Find<Entry>();And
Combines all the queries together using AND operator
| Name | Type | Description |
|---|---|---|
| queryObjects | List<Query> | List of Query instances on which AND query executes. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");
Query query1 = contentTypeObj.Query();
query1.Where("username","content");
Query query2 = contentTypeObj.Query();
query2.Where("email_address","[email protected]");
List<Query> queryList = new List<Query>();
queryList.Add(query1);
queryList.Add(query2);
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().And(queryList).Find<Entry>();Or
Add a constraint to fetch all entries which satisfy any queries.
| Name | Type | Description |
|---|---|---|
| queryObjects | List<Query> | List of Query instances on which OR query executes. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentType contentTypeObj = stack.ContentType("contentType_id");
Query query1 = contentTypeObj.Query();
query1.Where("username","content");
Query query2 = contentTypeObj.Query();
query2.Where("email_address","[email protected]");
List<Query> queryList = new List<Query>();
queryList.Add(query1);
queryList.Add(query2);
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Or(queryList).Find<Entry>();Except
Specifies list of field uids that would be excluded from the response.
| Name | Type | Description |
|---|---|---|
| fieldUid | string[] | field uid which get excluded from the response. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Except(new String[] {"name", description }).Find<Entry>();Only
Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
| Name | Type | Description |
|---|---|---|
| fieldUid | string[] | Array of the 'only' keys to be included in response. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Only(new String[] {"name", description }).Find<Entry>();Exists
Add a constraint that requires, a specified key exists in response.
| Name | Type | Description |
|---|---|---|
| key | string | The key to be constrained. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Exist("title").Find<Entry>();NotExists
Add a constraint that requires, a specified key does not exists in response.
| Name | Type | Description |
|---|---|---|
| key | string | The key to be constrained. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().NotExist("title").Find<Entry>();NotEqualTo
Add a constraint to the query that requires a particular key's entry to be not equal to the provided value.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object | The object that must not be equaled. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().NotEqualTo("title", "Demo").Find<Entry>();Where
Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object | Field value which get included from the response. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Where("title", "Demo").Find<Entry>();NotContainedIn
Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object[] | The list of values the key object should not be. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().NotContainedIn("title", new Object[]{ "Demo", "Welcome"}).Find<Entry>();ContainedIn
Add a constraint to the query that requires a particular key's entry to be contained in the provided array.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object[] | The possible values for the key's object. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().ContainedIn("title", new Object[]{ "Demo", "Welcome"}).Find<Entry>();LessThanOrEqualTo
Add a constraint to the query that requires a particular key entry to be less than or equal to the provided value.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object | The value that provides an upper bound or equal. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().LessThanOrEqualTo("age", 20).Find<Entry>();LessThan
Add a constraint to the query that requires a particular key entry to be less than the provided value.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object | The value that provides an upper bound. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().LessThan("age", 20).Find<Entry>();GreaterThanOrEqualTo
Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided value.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object | The value that provides a lower bound or equal. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().GreaterThanOrEqualTo("age", 20).Find<Entry>();GreaterThan
Add a constraint to the query that requires a particular key entry to be greater than the provided value.
| Name | Type | Description |
|---|---|---|
| key | string | the key to be constrained. |
| value | Object | The value that provides an lower bound. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().GreaterThan("age", 20).Find<Entry>();Find
Execute a Query and Caches its result (Optional)
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Find<Entry>();FindOne
Execute a Query and Caches its result (Optional)
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().FindOne<Entry>();Count
Retrieve only count of entries in result.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack.ContentType("content_Type_uid").Query().Count();Variants
The variants method retrieves details of a specific entry variant or an array of entry variants based on the applied query.
When Personalize creates a variant in the CMS, it assigns a "Variant Alias" to identify that specific variant. When fetching entry variants using the Delivery API, you can pass variant aliases in place of variant UIDs in the x-cs-variant-uid header.
| Name | Type | Description |
|---|---|---|
| variant_headers (required) | string | string[] | List of variants |
Example:
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
ContentstackCollection<Entry> collection = await stack
.ContentType("content_Type_uid")
.Query()
.Variant(new String[]{"variant_uid1/variant_alias1", "variant_uid2/variant_alias2"})
.Find<Entry>();