This project is not covered by Drupal’s security advisory policy.

Maintainer's Note: This module is no longer maintained. It was created prior to the great work done on the JSON API module, which is targeted for inclusion in Drupal 8.4 as an experimental module. The code written in this module to construct complex client-side queries has been extracted and incorporated into the JSON API module and is now even more powerful. So, with the JSON API module you can get all the same great features, plus much more. Happy developing!

If you're looking for documentation on writing Entity Queries in Drupal 8, look here: Entity QueryInterface.

Entity Query API fills the gap between Drupal 8's built-in RESTful Services and Views with an easy to use, out-of-the-box means for loading, filtering and paging entities in a RESTful style. Essentially, this module provides an API to the Entity QueryInterface.

Any enabled entity gets an endpoint at /entity/{entity_type} which responds to GET requests.

You can apply conditions, sorts, and ranges to your query for the given entity type.


  1. Download the module and enable it as usual. There are no dependencies outside Drupal core.
  2. Navigate to Configuration > Web Services > Entity Query API (/admin/config/services/entityqueryapi).
  3. Enable the content or configuration entities that you would like to be able to query.


The following describes Entity Query API's query string syntax. However, if you are doing anything more involved, we recommend using a JavaScript library to craft these query strings for you. The drupal-api package on NPM is maintained in tandem with this module. Even better, Waterwheel is client-side library for taking advantage of Drupal Core's REST module and the Entity Query API, it uses drupal-api under the hood.

You can limit your query by adding range parameters to your query string. For example:


* New lines and tabs just added for readability

Will limit your query to first 10 nodes fetched.

You can sort your query by adding sort parameters to your query string. You can have multiple sorts by numbering them. For example:


* New lines and tabs just added for readability

Will sort your results by newest nodes, then alphabetically by title.

You can filter your query by adding condition parameters to your query string. Like sorts, you can have multiple conditions by numbering them. For example:


* New lines and tabs just added for readability

Will filter your results to be all nodes created since the timestamp 1459973680. All operators supported by the QueryInterface::condition method except for 'IN', 'NOT IN', and 'BETWEEN' are supported (future support planned). However, to make url escaping more simple, some of the operators have been remapped to alpha characters. The array below illustrates that mapping.

$operator_dict = array(                                                         
  'EQ'      => '=',                                                             
  'NOTEQ'   => '<>',                                                            
  'GT'      => '>',                                                             
  'GTEQ'    => '>=',                                                            
  'LT'      => '<',                                                             
  'LTEQ'    => '<=',                                                            

Condition Groups
You can group conditions using AND and OR groups by adding group parameters. Like sorts and conditions, you can have multiple groups by numbering them. As an example, imagine you want all nodes tagged with 'red' - AND 'blue' OR 'green'. The pseudo-code might look like this: if ( in_array('red', $clrs) && ( in_array('blue', $clrs) || in_array('green', $clrs) ) ). To recreate the OR group between blue and green, you would construct a query string that looks something like this:


* New lines and tabs just added for readability

Groups can also be nested within groups. If we were adding a group within group_0 in our previous example, it might look like this: &group_1[conjunction]=AND&group_1[group]=group_0.

Exists and notExists
You can use the exists and notExists shorthands (they're just 'IS NOT NULL' conditions under the hood) too. The query parameter is exists_N, notExists are created by setting the condition subproperty to 'FALSE'. Thus, a notExists look like this:


* New lines and tabs just added for readability

Putting It All Together
All of the above parameters can be mixed and matched to describe exactly the query that you want. For example, if we wanted the 5 most recent 'article' nodes created, we would construct a query string as follows:


* New lines and tabs just added for readability

Supporting organizations: 

Project Information