Logical Operators

Modified on Wed, 11 Mar at 1:05 PM

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


OperatorDescriptionExample Usage
eqEqual toproperty eq 'value'
neNot equal toproperty ne 'value'
gtGreater thanproperty gt 10
ltLess thanproperty lt 10
geGreater than or equal toproperty ge 10
leLess than or equal toproperty le 10
andLogical ANDproperty1 eq 'value1' and property2 lt 5
orLogical ORproperty1 eq 'value1' or property2 gt 10
inMatches any value in a listproperty in ('value1', 'value2')


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' and price is greater than 100:
$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 in the 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.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article