Chord OMS
Chord OMS Overview
Chord OMS API Endpoint Filtering (Ransack)
2min
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 https //github com/activerecord hackery/ransack/blob/master/lib/ransack/locale/en yml#l15 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