1. Home
  2. Knowledge Base
  3. FAQs
  4. Consuming the service
  5. Filters with OData and URL conventions

Filters with OData and URL conventions

If you need to add filtering logic to your API, here’s a quick guide with the most common operators:

Example:

/Order?$filter=CreatedOn gt 2006-12-30T23:59:59.99Z

 

The Equals operator (or ‘eq’) evaluates to true if the left operand is equal to the right operand, otherwise if evaluates to false.

Ex.: /Order?$filter=OrderStatusId eq 5

The URL above will return all the Orders with OrderStatusId = 5 (Approved)

 

Other operators include:

  • Not Equals (or ‘ne’)
  • Greater Than (or ‘gt’)
  • Greater Than or Equal (or ‘ge’)
  • Less Than (or ‘lt’)
  • Less Than (or ‘le’)
  • Logical And (or ‘and’)
  • Logical Or (or ‘or’)
  • Logical Negation Operator (or ‘not’)

The following examples illustrate the use and semantics of each of the logical operators:

 

Product?$filter=Name eq ‘Milk’ (Requests all products with a Name equal to ‘Milk’)

Product?$filter=Name ne ‘Milk’ (Requests all products with a Name not equal to ‘Milk’)

Product?$filter=Name gt ‘Milk’ (Requests all products with a Name greater than ‘Milk’)

Product?$filter=Name ge ‘Milk’ (Requests all products with a Name greater than or equal to ‘Milk’)

Product?$filter=Name lt ‘Milk’ (Requests all products with a Name less than ‘Milk’)

Product?$filter=Name le ‘Milk’ (Requests all products with a Name less than or equal to ‘Milk’)

Product?$filter=Name eq ‘Milk’ and Price lt ‘2.55M’ (Requests all products with the Name ‘Milk’ that also have a Price less than 2.55)

Product?$filter=Name eq ‘Milk’ or Price lt ‘2.55M’ (Requests all products that either have the Name ‘Milk’ or have a Price less than 2.55)

Product?$filter=not endswith(Name, ‘ilk’) (Requests all products that do not have a Name that ends with ‘ilk’)

 

For more reference and examples, refer to the official OData documentation page on URL conventions:

https://www.odata.org/documentation/odata-version-3-0/url-conventions/

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support