Passworks API supports sorting for the most common attributes via query string.
Here is an example searching for a Coupon campaign with the name equal (name_eq) to "Una Salus Victus"
GET https://api.passworks.io/v2/coupons/?q[name_eq]=Una Salus Victus
You can ignore the trailing slash in the end of the URL.
The following predicates are also available:
|*_match||matches with LIKE, e.g. q[email_matches]=%@gmail.com|
|*_lteq||less than or equal|
|*_gteq||greater than or equal|
So if you wish to search for the attribute "name" containing the word "House" you will have
Best pratices: Escaping query parameters
Don't forget to escape the URL query parameters before submiting them to the API endpoint.
Ordering attributes is also simple to accomplish see the following example ordering the
created_at attribute in ascending order (asc)
To request ordering from a given attribute with a direction (ascending or descending) you need to to use the
q[s]= following the attribute that you wish to order
created_at following with a plus (+) signal and the direction of sorting
So sorting the for the attribute name in descending order would be doing the following:
Sorting multiple parameters, ordering and using pagination at the same time
You can append one or more filters to the query string then event apply the desired sort and finally specify a given page to be retrieved.
See the following example filtering for two parameters "name" (equal) and "redeem_count" (equal) and then asking for the results sorted by "created_at" in descending order and finally asking for the second page (page=2) of the results displaying 4 results per page (per_page=4).
GET https://api.passworks.io/v2/coupons/?q[name_eq]=Una Salus Victus&q[redeem_count_eq]=0&q[s]=created_at+desc&page=2&per_page=4
You can mix and match the query parameters the order doesn't matter.
You can sort and order the attributes inside the following endpoints:
Sort campaign collection attributes
Sort passes collection side a specific campaign
Sort registrations collection inside a specific campaign
Sort redeems collection inside a specific campaign
Sort registrations collection inside a specific campaign and pass
Sort redeems collection inside a specific campaign and pass
Please replace the
pass_idwith the appropriate resource ID from your side.