Additional list parameters
Previous tutorials only use simple list that returns the IDs of the resources, but you can actually get more details, sort and filter the list.
Display parameter
You can specify which fields you want for each resource using the display
parameter.
Key |
Value |
Result |
display |
full |
Returns all the fields of the resource |
|
[field1,field2,...] |
Returns only the fields specified in this array |
Result |
API call |
PHP Webservice lib options |
Include all fields from the products resource |
/api/products/?display=full |
$opt = [
'resource' => 'products',
'display' => 'full'
];
|
Include only the ID from the carriers resource |
/api/carriers/?display=[id] |
$opt = [
'resource' => 'carriers',
'display' => '[id]'
];
|
Only include the name and value fields from the configurations resource |
/api/configurations/?display=[name,value] |
$opt = [
'resource' => 'configurations',
'display' => '[name,value]'
];
|
Filter parameter
You can filter the expected result with the filter
parameter
Key |
Value |
Result |
filter[field] |
[1|5]
|
OR operator: list of possible values |
|
[1,10]
|
Interval operator: define interval of possible values |
|
[John]
|
Literal value (not case sensitive) |
|
[Jo]%
|
Begin operator: fields begins with the value (not case sensitive) |
|
%[hn]
|
End operator: fields ends with the value (not case sensitive) |
|
%[oh]%
|
Contains operator: fields contains the value (not case sensitive) |
Result |
API call |
PHP Webservice lib options |
Only the customers whose ids are 1 or 5 |
/api/customers/?filter[id]=[1|5]
|
$opt = [
'resource' => 'customers',
'filter[id]' => '[1|5]'
];
|
Only the customers whose ids are between 1 and 10 |
/api/customers/?filter[id]=[1,10]
|
$opt = [
'resource' => 'customers',
'filter[id]' => '[1,10]'
];
|
Only the customers whose first name is “John” |
/api/customers/?filter[firstname]=[John]
|
$opt = [
'resource' => 'customers',
'filter[firstname]' => '[John]',
];
|
Only the manufacturers whose name begins with “Appl” |
/api/manufacturers/?filter[name]=[appl]%
|
$opt = [
'resource' => 'manufacturers',
'filter[name]' => '[appl]%',
];
|
Sort parameter
You can sort the expected result with the sort
parameter
Key |
Value |
Result |
sort |
[{fieldname}_{ASC|DESC}]
|
The sort value is composed of a field name and the expected order separated by a _ |
Result |
API call |
PHP Webservice lib options |
Sort the customers in alphabetical order according to last name |
/api/customers/?sort=[lastname_ASC]
|
$opt = [
'resource' => 'customers',
'sort' => '[lastname_ASC]'
];
|
Sort the customers in alphabetical order according to last name, then by biggest ID first |
/api/customers/?sort=[lastname_ASC,id_DESC]
|
$opt = [
'resource' => 'customers',
'sort' => '[lastname_ASC,id_DESC]'
];
|
If you need to sort by the date field you need to add &date=1
in your request.
Final request will be: /api/customers/?sort=[date_add_DESC]&date=1
Limit parameter
You can define a limit to the expected result with the limit
parameter (which may allow you to perform pagination)
Key |
Value |
Result |
limit |
[offset,]limit |
Either define offset and limit separated by a , (ex: 1,5 ) or the limit only (offset is 0-indexed) |
Result |
API call |
PHP Webservice lib options |
Only include the first 5 states |
/api/states/?limit=5 |
$opt = [
'resource' => 'states',
'limit' => '5'
];
|
Only include the first 5 states starting from the 10th element |
/api/states/?limit=9,5 |
$opt = [
'resource' => 'states',
'limit' => '9,5'
];
|