---
title: Chord OMS API Endpoint Filtering (Ransack)
slug: oms/chord-oms-api-endpoint-filtering-ransack
docTags: 
createdAt: 2023-08-23T21:01:24.070Z
---

Best practices for filtering with the ***Chord OMS APIs***

The Chord OMS leverages ***Ransack,*** which is a native searching/filtering mechanism built for Ruby on Rails applications. For more information, [see here](https://activerecord-hackery.github.io/ransack/).

To use/filter by a given predicate, append it as a query parameter to the end of any API endpoint. The format is  `API Endpoint + “?q[{FIELD-TO-FILTER-BY_PREDICATE}]=VALUE”`

For example:

`/api/orders/mine?q[state_eq]=complete`

# Possible Predicates:

| Predicate                 | Description                                          | Notes                                                                                                  |
| ------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| \*\_eq                    | equal                                                |                                                                                                        |
| \*\_not\_eq               | not equal                                            |                                                                                                        |
| \*\_matches               | matches with LIKE                                    | e.g. q\[email\_matches]=%@gmail.com                                                                    |
| \*\_does\_not\_match      | does not match with LIKE                             |                                                                                                        |
| \*\_matches\_any          | Matches any                                          |                                                                                                        |
| \*\_matches\_all          | Matches all                                          |                                                                                                        |
| \*\_does\_not\_match\_any | Does not match any                                   |                                                                                                        |
| \*\_does\_not\_match\_all | Does not match all                                   |                                                                                                        |
| \*\_lt                    | less than                                            |                                                                                                        |
| \*\_lteq                  | less than or equal                                   |                                                                                                        |
| \*\_gt                    | greater than                                         |                                                                                                        |
| \*\_gteq                  | greater than or equal                                |                                                                                                        |
| \*\_present               | not null and not empty                               | Only compatible with string columns. Example: q\[name\_present]=1 (SQL: col is not null AND col != '') |
| \*\_blank                 | is null or empty.                                    | (SQL: col is null OR col = '')                                                                         |
| \*\_null                  | is null                                              |                                                                                                        |
| \*\_not\_null             | is not null                                          |                                                                                                        |
| \*\_in                    | match any values in array                            | e.g. q\[name\_in]\[]=Alice\&q\[name\_in]\[]=Bob                                                        |
| \*\_not\_in               | match none of values in array                        |                                                                                                        |
| \*\_lt\_any               | Less than any                                        | SQL: col \< value1 OR col \< value2                                                                    |
| \*\_lteq\_any             | Less than or equal to any                            |                                                                                                        |
| \*\_gt\_any               | Greater than any                                     |                                                                                                        |
| \*\_gteq\_any             | Greater than or equal to any                         |                                                                                                        |
| \*\_lt\_all               | Less than all                                        | SQL: col \< value1 AND col \< value2                                                                   |
| \*\_lteq\_all             | Less than or equal to all                            |                                                                                                        |
| \*\_gt\_all               | Greater than all                                     |                                                                                                        |
| \*\_gteq\_all             | Greater than or equal to all                         |                                                                                                        |
| \*\_not\_eq\_all          | none of values in a set                              |                                                                                                        |
| \*\_start                 | Starts with                                          | SQL: col LIKE 'value%'                                                                                 |
| \*\_not\_start            | Does not start with                                  |                                                                                                        |
| \*\_start\_any            | Starts with any of                                   |                                                                                                        |
| \*\_start\_all            | Starts with all of                                   |                                                                                                        |
| \*\_not\_start\_any       | Does not start with any of                           |                                                                                                        |
| \*\_not\_start\_all       | Does not start with all of                           |                                                                                                        |
| \*\_end                   | Ends with                                            | SQL: col LIKE '%value'                                                                                 |
| \*\_not\_end              | Does not end with                                    |                                                                                                        |
| \*\_end\_any              | Ends with any of                                     |                                                                                                        |
| \*\_end\_all              | Ends with all of                                     |                                                                                                        |
| \*\_not\_end\_any         |                                                      |                                                                                                        |
| \*\_not\_end\_all         |                                                      |                                                                                                        |
| \*\_cont                  | Contains value                                       | uses LIKE                                                                                              |
| \*\_cont\_any             | Contains any of                                      |                                                                                                        |
| \*\_cont\_all             | Contains all of                                      |                                                                                                        |
| \*\_not\_cont             | Does not contain                                     |                                                                                                        |
| \*\_not\_cont\_any        | Does not contain any of                              |                                                                                                        |
| \*\_not\_cont\_all        | Does not contain all of                              |                                                                                                        |
| \*\_i\_cont               | Contains value with case insensitive                 | uses ILIKE                                                                                             |
| \*\_i\_cont\_any          | Contains any of values with case insensitive         |                                                                                                        |
| \*\_i\_cont\_all          | Contains all of values with case insensitive         |                                                                                                        |
| \*\_not\_i\_cont          | Does not contain with case insensitive               |                                                                                                        |
| \*\_not\_i\_cont\_any     | Does not contain any of values with case insensitive |                                                                                                        |
| \*\_not\_i\_cont\_all     | Does not contain all of values with case insensitive |                                                                                                        |
| \*\_true                  | is true                                              |                                                                                                        |
| \*\_false                 | is false                                             |                                                                                                        |

***See full list: &#xA0;***[https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/locale/en.yml#L15](https://github.com/activerecord-hackery/ransack/blob/main/lib/ransack/locale/en.yml)***&#x20;&#x20;***

# Example/Common Filter Scenarios

- If you would like to see all completed orders for your current user:
  - `/api/orders/mine?q[state_eq]=complete`
- If you would like to see all subscriptions for a given user
  - `/api/subscriptions?q[user_id_in]=:id`
- If you would like to see all completed orders for a giver user:
  - `api/orders?q[user_id_eq]={user_id}&q[state_eq]=complete`

