Logical Operators

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

Operator Description Example Usage
eq Equal to property eq 'value'
ne Not equal to property ne 'value'
gt Greater than property gt 10
lt Less than property lt 10
ge Greater than or equal to property ge 10
le Less than or equal to property le 10
and Logical AND property1 eq 'value1' and property2 lt 5
or Logical OR property1 eq 'value1' or property2 gt 10
in Matches any value in a list property 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 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.