Overview
Logical operators are used to combine conditions or compare property values in filter expressions. They are applied based on the data type of the corresponding property.
Supported Functions
Syntax
Logical operators follow this general syntax:
[property operator value]
Examples
Equal to a specific value:
$filter=property eq 'value'
- Example: Retrieve items where
cat_title
is'Products'
:
$filter=[cat_title eq 'Products']
Combine conditions with AND:
$filter=property1 eq 'value1' and property2 gt 5
- Example: Retrieve items where
category
is'electronics'
andprice
is greater than100
:
$filter=[category eq 'electronics' and price gt 100]
Use OR for alternative conditions:
$filter=property1 eq 'value1' or property2 eq 'value2'
- Example: Retrieve items where
status
is'active'
or'pending'
:
$filter=[status eq 'active' or status eq 'pending']
How to Use EQ and OR in a Request
- When constructing your API request, add the EQ and OR functions on filter parameter.
http://api2.saleslayer.com/rest/Catalog/Categories?$select=[cat_title,cat_description,cat_ref]&$expand=[Products]&$filter=[cat_title eq 'Products' or cat_ref eq 'LPG']
Response Format
{
"value": [
{
"cat_title": {
"en": "Logic Programming & Graphics"
},
"cat_description": {
"en": "Logic Programming & Graphics"
},
"cat_ref": "LPG",
"Products@count": 3
}
],
"@count": 2
}
Using String Functions with Logical Operators
String functions can be combined with logical operators for complex filtering:
$filter=startswith(name, 'Pro') and contains(description, 'advanced')
Notes
- Refer to the metadata of the root resource to confirm the data types of properties and construct valid filter expressions.