Query

View as Markdown

Query

The Query provides entries based on queries applied

where

Get entries containing the field values matching the condition in the query.

NameTypeDescription
fieldUid (required)String

The field uid

queryOperation (required)QueryOperation

The QueryOperation

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.where("fieldUid", QueryOperation);

skip

The number of objects to skip before returning any.

NameTypeDescription
skipCount (required)Int

No of objects to skip from returned objects

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.skip(4);

query

Add a custom query against specified key.

NameTypeDescription
key (required)String

key for the query

value (required)String

value for the query

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.addQuery("param_key", "param_value");

param

This method adds key and value to an Entry.

NameTypeDescription
key (required)String

key by which you can sort the results in descending order

value (required)String

value of the param against the key

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.param("Key", "Value");

orderByDescending

Sort the results in descending order with the given key.

NameTypeDescription
key (required)String

key by which you can sort the results in descending order

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.orderByDescending("descendingKey");

orderByAscending

sort the results in ascending order with the given key.

NameTypeDescription
key (required)String

key by which you can sort the results in ascending order

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.ascending("ascKey");

limit

A limit on the number of objects to return.

NameTypeDescription
limitCount (required)int

the count you want to limit your response

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.limit(2);

addQuery

Add a custom query against specified key. parameters The key and value pair that will be added to the Query

NameTypeDescription
parameters (required)Map

comma-separated string value

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.addParams("keyword1", "keyword2", "keyword3");

addParams

This method adds key and value to the Query as Query parameter.

NameTypeDescription
key (required)String

Key of the query parameter

value (required)String

Value of the Query parameter against the key

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('contentType').entry().query();

query.addParam("Key", "Value")

includeBranch

includes branch in the response

import Contentstack


final stack = contentstack.stack(apiKey, delieveryToken, environment)

final query = stack.contentType('room').entry().query();

query.includeBranch()

whereReference

Get entries having values based on referenced fields This query retrieves all entries that satisfy the query conditions made on referenced fields.

NameTypeDescription
referenceUid (required)String

The referenced uid

reference (required)QueryReference

It accepts Enum type QueryReference.include() OR QueryReference.NotInclude() and it accepts instance of Query

import Contentstack

final query = stack.contentType('room').entry().query();

query.referenceSearch('fieldUid', QueryReference.include(query: query));

  await query.find().then((response){

    print(response);

});

setHeader

adds header to the request

NameTypeDescription
key (required)String

key of the header

value (required)String

value of the header against the key

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.setHeader("key", "value")

removeHeader

Removed header from the request by key

NameTypeDescription
key (required)String

key of the header

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.removeHeader("key")

operator

entries that satisfy at least one of the given conditions provided

NameTypeDescription
listOfQuery (required)QueryOperator.and(queryObjects: List<Query>)

QueryOperator using and/or functions that accepts list of queries

import Contentstack

final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");final query = stack.contentType('contentTypeUid').entry().query();query.operator(QueryOperator.OR);

final stackInstance1 = Credential.stack(); final queryBase1 = stackInstance1.contentType('room').entry().query(); queryBase1.where('title', QueryOperation.equals(value: 'Room 13')); 

final stackInstance2 = Credential.stack(); final queryBase2 = stackInstance2.contentType('room').entry().query(); queryBase2.where('attendee', QueryOperation.equals(value: 20)); 

final List listOfQuery = [queryBase1, queryBase2]; 

query.operator(QueryOperator.or(queryObjects: listOfQuery));

await query.find().then((response)

{ 

  print(response.toString()); 

}).catchError((onError){ 

  print(onError); 

});

only

provides data that contains only mentinoed keywords

NameTypeDescription
fieldUid (required)List<String>

Array of the only reference keys to be included in response

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.only(fieldUid);

locale

[locale] is the code of the language in which the entries need to be included.

NameTypeDescription
locale (required)String

[locale] is code of the language of which the entries needs to be included.

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.locale("locale_code");

includeReferenceContentTypeUID

This method also includes the content type UIDs of the referenced entries returned in the response

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.includeReferenceContentTypeUID();

includeReference

When you fetch an entry of a content type that has a reference field, by default, the content of the referred entry is not fetched. It only fetches the UID of the referred entry, along with the content of the specified entry

NameTypeDescription
referenceFieldUid (required)String

Key who has reference to some other class object

includeReferenceFieldIncludeReference

provides three options, none, only and except i.e accepts list of fieldUid

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.includeReference("referenceFieldUid", IncludeReference.except(fieldUidList: fieldUid));;

includeEmbeddedItems

Include Embedded Objects (Entries and Assets) along with entry/entries details

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.includeEmbeddedItems();

includeFallback

Retrieve the published content of the fallback locale if an entry is not localized in specified locale.

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.includeFallback();

includeContentType

Include Content Type of all returned objects along with objects

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.includeContentType();

except

Specifies list of field uids that would be excluded from the response. [fieldUid] field uid which get excluded from the response.

NameTypeDescription
fieldUid (required)List<String>

fieldUid is String type of List

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

query.except(fieldUid);

addParam

This method adds key and value to an Entry.

NameTypeDescription
key (required)String

key of the parameter

value (required)String

value of the param against the key

import Contentstack


final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");

final query = stack.contentType('contentTypeUid').entry().query();

entry.addParam("key", "value");