Documente Academic
Documente Profesional
Documente Cultură
Specifying 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 speci ed 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>
where:
Condition Notes
eq Equals.
gt Greater than
lt Less than
lteq Less than or equal
null Null
The filter_groups array de nes one or more filters. Each lter de nes a search term, and
the field, value, and condition_type of a search term must be assigned the same index
number, starting with 0. Increment additional terms as needed.
Simple search
The Magento CE sample data uses the category_gear eld to describe the categories for each
item listed under Gear on sample store. Each item can be assigned to multiple categories.
Electronics are assigned the code 86. The following example returns all gear tagged as
electronics.
GEThttp://<magento_host>/rest/V1/products/?
searchCriteria[filter_groups][0][filters][0][field]=category_gear&
searchCriteria[filter_groups][0][filters][0][value]=86&
searchCriteria[filter_groups][0][filters][0][condition_type]=finset
The system creates an array, as shown in the following pseudo-code.
searchCriteria=>[
'filterGroups'=>[
0=>[
'filters'=>[
0=>[
'field'=>'category_gear',
'value'=>'86',
'condition_type'=>'finset'
]
]
]
]
GEThttp://<magento_host>/rest/V1/invoices?
searchCriteria[filter_groups][0][filters][0][field]=created_at&
searchCriteria[filter_groups][0][filters][0][value]=2016070100:00:00&
searchCriteria[filter_groups][0][filters][0][condition_type]=gt
Logical OR search
The following example searches for all products whose names contain the string Leggings or
Parachute. The instances of %25 in the example are converted into the SQL wildcard character
%.
GEThttp://<magento_host>/index.php/rest/V1/products?
searchCriteria[filter_groups][0][filters][0][field]=name&
searchCriteria[filter_groups][0][filters][0][value]=%25Leggings%25&
searchCriteria[filter_groups][0][filters][0][condition_type]=like&
searchCriteria[filter_groups][0][filters][1][field]=name&
searchCriteria[filter_groups][0][filters][1][value]=%25Parachute%25&
searchCriteria[filter_groups][0][filters][1][condition_type]=like
The search returns 14 products that contain the string Leggings in the name eld and 14
products that contain the string Parachute.
GEThttp://<magento_host>/rest/V1/products?
searchCriteria[filter_groups][0][filters][0][field]=sku&
searchCriteria[filter_groups][0][filters][0][value]=WSH%2531%25&
searchCriteria[filter_groups][0][filters][0][condition_type]=like&
searchCriteria[filter_groups][1][filters][0][field]=price&
searchCriteria[filter_groups][1][filters][0][value]=30&
searchCriteria[filter_groups][1][filters][0][condition_type]=lt
GEThttp://<magento_host>/rest/V1/products?
searchCriteria[filter_groups][0][filters][0][field]=sku&
searchCriteria[filter_groups][0][filters][0][value]=WSH%2529%25&
searchCriteria[filter_groups][0][filters][0][condition_type]=like&
searchCriteria[filter_groups][0][filters][1][field]=sku&
searchCriteria[filter_groups][0][filters][1][value]=WP%2529%25&
searchCriteria[filter_groups][0][filters][1][condition_type]=like&
searchCriteria[filter_groups][1][filters][0][field]=price&
searchCriteria[filter_groups][1][filters][0][value]=40&
searchCriteria[filter_groups][1][filters][0][condition_type]=from&
searchCriteria[filter_groups][2][filters][0][field]=price&
searchCriteria[filter_groups][2][filters][0][value]=49.99&
searchCriteria[filter_groups][2][filters][0][condition_type]=to