Query
Query
The Get all entries request fetches the list of all the entries of a particular content type. It returns the content of each entry in JSON format. You need to specify the environment and locale of which you want to get the entries. We can apply filters on query also.
removeHeader
Remove header key
| Name | Type | Description |
|---|---|---|
| key (required) | String | key of the header you want to remove |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.removeHeader(key)getContentType
Gets the content type
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.getContentType()where
Add a constraint to fetch all entries that contains given value against specified key
| Name | Type | Description |
|---|---|---|
| key (required) | String | key of query parameter |
| value (required) | Object | value of query param |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.where("uid", "entry_uid");addQuery
Add a custom query against specified key.
| Name | Type | Description |
|---|---|---|
| key (required) | String | key of query parameter |
| value (required) | String | value of query param |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.addQuery("key", "value");removeQuery
Remove provided query key from custom query if exist.
| Name | Type | Description |
|---|---|---|
| key (required) | String | Query name to remove. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.removeQuery(key);and
Combines all the queries together using AND operator
| Name | Type | Description |
|---|---|---|
| queryObjects (required) | ArrayList<Query> | List of Query instances on which AND query executes. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThan("due_date", "2013-06-25T00:00:00+05:30");
Query query = projectClass.query();
query.where('username','something');
Query subQuery = projectClass.query();
subQuery.where('email_address','[email protected]');
ArrayList<Query> array = new ArrayList<Query>();
array.add(query);
array.add(subQuery);
query.and(array);or
Add a constraint to fetch all entries which satisfy any queries.
| Name | Type | Description |
|---|---|---|
| queryObjects (required) | ArrayList<Query> | the value that provides an upper bound |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThan("due_date", "2013-06-25T00:00:00+05:30");
Query query = projectClass.query();
query.where('username','something');
Query subQuery = projectClass.query();
subQuery.where('email_address','[email protected]');
ArrayList<Query> array = new ArrayList<Query>();
array.add(query);
array.add(subQuery);
query.or(array);lessThan
Add a constraint to the query that requires a particular key entry to be less than the provided value.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | the value that provides an upper bound |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThan("due_date", "2013-06-25T00:00:00+05:30");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 (required) | String | The key to be constrained |
| values (required) | Object | The value that must be equalled. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.lessThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");greaterThan
Add a constraint to the query that requires a particular key entry to be greater than the provided value.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | The value that provides an lower bound. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.greaterThan("due_date", "2013-06-25T00:00:00+05:30");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 (required) | String | The key to be constrained |
| values (required) | Object | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.greaterThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");notEqualTo
Add a constraint to the query that requires a particular key's entry to be contained in the provided array
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notEqualTo("due_date", "2013-06-25T00:00:00+05:30");notContainedIn
Add a constraint to the query that requires a particular key's entry to be contained in the provided array
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| values (required) | Object[] | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.containedIn("severity", new Object[] { "Show Stopper", "Critical" });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 (required) | String | The key to be constrained |
| values (required) | Object[] | The list of values the key object should not be. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notContainedIn("severity", new Object[] { "Show Stopper", "Critical" });exists
Add a constraint that requires, a specified key exists in response
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.exists("status");notExists
Add a constraint that requires, a specified key does not exists in response.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.notExists("status");includeReference
Add a constraint that requires a particular reference key details
| Name | Type | Description |
|---|---|---|
| key (required) | String | key that to be constraineda |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeReference(key);tags
Include tags with which to search entries
| Name | Type | Description |
|---|---|---|
| key (required) | String[] | Comma separated array of tags with which to search entries. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.tags(new String[] { "tag1", "tag2" });ascending
Sort the results in ascending order with the given key. <br> Sort the returned entries in ascending order of the provided key.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to order by. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.ascending(key);descending
Sort the results in descending order with the given key. <br> Sort the returned entries in descending order of the provided key.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to order by. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.descending(key);only
Specifies an array of only keys in BASE object that would be included in the response.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | String[] |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();exceptWithReferenceUid
Specifies an array of only keys that would be included in the response
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | ArrayList<String> | Array of the only reference keys to be included in response |
| referenceFieldUid (required) | String | Key who has reference to some other class object |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
ArrayList<String> array = new ArrayList<String>();
array.add("description");
query.onlyWithReferenceUid(array, "for_bug");exceptWithReferenceUid
Specifies an array of except keys that would be excluded in the response.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
ArrayList<String> array = new ArrayList<String>();
array.add("description");
query.exceptWithReferenceUid(array, "for_bug");count
Retrieve count and data of objects in result
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.count();includeCount
Retrieve count and data of objects in result
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeCount();includeContentType
Include Content Type of all returned objects along with objects themselves
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeContentType();includeOwner
Include object owner's profile in the objects data.
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.
()skip
The number of objects to skip before returning any.
| Name | Type | Description |
|---|---|---|
| number (required) | int | Number of objects to skip from returned objects |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.skip(3)limit
A limit on the number of objects to return.
| Name | Type | Description |
|---|---|---|
| number (required) | int | Number of objects to limit. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.limit(3)regex
Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large data sets.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained. |
| regex (required) | String | The regular expression pattern to match |
| modifiers | Any of the following supported Regular expression modifiers. - use i for case-insensitive matching. - use m for making dot match newlines. - use x for ignoring whitespace in regex |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.regex("name", "^browser", "i");locale
Set Language using locale code.
| Name | Type | Description |
|---|---|---|
| locale (required) | String | language code |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.locale("locale-code");search
This method provides only the entries matching the specified value.
| Name | Type | Description |
|---|---|---|
| value (required) | String | value used to match or compare |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.search("header");find
Execute a Query and Caches its result (Optional)
| Name | Type | Description |
|---|---|---|
| callBack (required) | QueryResultsCallBack | QueryResultsCallBack object to notify the application when the request has completed. |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
}
});findOne
This Execute a Query and Caches its result (Optional)
| Name | Type | Description |
|---|---|---|
| callBack (required) | SingleQueryResultCallback | The key as string which needs to be added to the Query |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.findOne(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, <ENTRY> entry, Error error) {
}
});addParam
This method adds key and value to an Entry. Parameters
| Name | Type | Description |
|---|---|---|
| paramKey (required) | String | The key as string which needs to be added to the Query |
| paramValue (required) | String | The value as string which needs to be added to the Query |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.addParam(key, value);includeReferenceContentTypUid
This method also includes the content type UIDs of the referenced entries returned in the response
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
csQuery.includeReferenceContentTypUid()whereNotIn
Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query conditions made on referenced fields.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| queryObject (required) | Query | queryObject is Query object, so you can chain this call |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.whereIn("due_date", <span>query</span>);whereNotIn
Get entries having values based on referenced fields. This query works the opposite of $in_query and retrieves all entries that does not satisfy query conditions made on referenced fields.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key to be constrained |
| queryObject (required) | Query | Query object, so you can chain this call |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.whereNotIn("due_date",
);includeFallback
Includes language fallback in the query response
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeFallback();includeEmbeddedItems
Includes Embedded Items in the query response
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();
query.includeEmbeddedItems();includeBranch
Includes Branch in the entry response
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
Query query = stack.contentType("contentTypeUid").query();includeMetadata
Includes query metadata along with the response body.
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
Query query = stack.contentType("contentTypeUid").query();
query.includeMetadata();