Close [x]

searchCriteria

POST, PUT, and DELETE requests to the REST Web API require the service method parameters to be in the body of the request. For example, to create a Customer, you would specify a JSON array (or XML structure) in the body of the message.

For search APIs that invoke a *Repository::getList(SearchCriteriaInterface *) call, the searchCriteria must be specified in the URL of the GET request. The basic pattern for specifying the criteria is

searchCriteria[filter_groups][<index>][filters][<index>][field=<field_name>]
searchCriteria[filter_groups][<index>][filters][<index>][value=<search_value>]
searchCriteria[filter_groups][<index>][filters][<index>][condition_type=<operator>]

condition_type is optional if the operator is eq (equals).

For example, the following query finds all users whose first name starts with 鈥淛o鈥.

GET http://<magento_host>/rest/V1/customers/search?
searchCriteria[filterGroups][0][filters][0][field]=firstname&
searchCriteria[filterGroups][0][filters][0][value]=Jo%25&
searchCriteria[filterGroups][0][filters][0][condition_type]=like

The system creates an array, as shown in the following pseudo-code.

searchCriteria => [
聽聽'filterGroups' => [
聽聽聽聽0 => [
聽聽聽聽聽聽'filters' => [
聽聽聽聽聽聽聽聽聽0 => [
聽聽聽聽聽聽聽聽聽聽聽'field' => 'firstname',
聽聽聽聽聽聽聽聽聽聽聽'value' => 'Jo%',
聽聽聽聽聽聽聽聽聽聽聽'condition_type' => 'like'
聽聽聽聽聽聽聽聽聽]
聽聽聽聽聽聽]
聽聽聽聽]
聽聽] 

The following example searches for products whose attributes are size=Large and color=Red. The generated array follows.

GET http://<magento_host>/rest/V1/products?`
searchCriteria[filter_groups][0][filters][0][field]=size&
searchCriteria[filter_groups][0][filters][0][value]=Large&
searchCriteria[filter_groups][0][filters][0][condition_type]=eq&
searchCriteria[filter_groups][0][filters][1][field]=color&
searchCriteria[filter_groups][0][filters][1][value]=Red&
searchCriteria[filter_groups][0][filters][1][condition_type]=eq
searchCriteria => [
聽聽'filterGroups' => [
聽聽聽聽0 => [
聽聽聽聽聽聽'filters' => [
聽聽聽聽聽聽聽聽聽0 => [
聽聽聽聽聽聽聽聽聽聽聽'field' => 'size',
聽聽聽聽聽聽聽聽聽聽聽'value' => 'Large',
聽聽聽聽聽聽聽聽聽聽聽'condition_type' => 'eq'
聽聽聽聽聽聽聽聽聽]
聽聽聽聽聽聽聽聽聽1 => [
聽聽聽聽聽聽聽聽聽  'color' => 'color',
聽聽聽聽聽聽聽聽聽  'value' => 'Red',
聽聽聽聽聽聽聽聽聽  'condition_type' => 'eq'
聽聽聽聽聽聽聽聽聽]
聽聽聽聽聽聽]
聽聽聽聽]
聽聽]