The filters in our API work by sending optional query parameters that have values that work analogous to the way queries work in mongodb.
For example, have in mind the query parameter amount=value
sent in the request to obtain transactions.
The word amount can be substituted for the name of any field present in the schema of transactions or simply with the string $or. In this case if the value sent is 100
, you would get a response with all the transactions that have an amount of exactly 100
. More complex queries can be done, and a simplified list of available options for the value is as follows:
value
'{"$lt": value}'
'{"$lte": value}'
'{"$gt": value}'
'{"$gte": value}'
'{"$regex": value}'
'{"$in": "[\"first_value\", \"second_value\"]"}'
'{"nested_field": value}'
'{"nested_field": {operator: value}}'
And the final request should look something like this:
https://api.cardda.com/v1/banking/resource?some_field=any_of_the_listed_options
Where each operator of the listed options means the following:
- plain value: strict match between the value of the field and this value.
- $gt: greater than.
- $gte: greater than or equal to.
- $lt: less than .
- $lte: less than or equal to.
- $regex: regular expression to match the content of the field.
- $in: numerous options where the value of the field must match at least one.
On the other hand, if field used is the string $or as mentioned before, it means that you want to apply a logical or with several filters, so it is expected that the value of the query param would be an array, where each entry corresponds to an object with one of the filters previously explained, where each key corresponds to a field, and each value corresponds to simply a value, or an operation as explained before. For example if the field is the string $or, the expected value is something like:
[
{
"status": {
"$in": "[\"pending\", \"approved\"]"
}
}, {
"amount": {
"$in": "[100, 200]"
}
}
]
And the request would look something like this:
https://api.cardda.com/v1/banking/resource?$or=[{"status": {"$in": "[\"pending\", \"approved\"]"}}, {"amount": {"$in": "[100, 200]"}}]
As a tip: have in mind that an $and operation for a specific field, just consists in sending the field as the query param, and in the value, send multiple operators, and each one of those would be an expression in the wanted $and operation. For example, the query parameter "amount" with a value of:
{
"$lt": 100,
"$gt": 50
}
Results in a query for all records that have a field amount that is greater than 50 and less than 100.
Also worth mentioning is the fact that you can send multiple query params of this style and the result will be those records that meet all the applied filters.