Filters balances using advanced criteria specified in a JSON request body. Provides more sophisticated filtering capabilities than the query parameter approach, including sorting, counting, and complex filter combinations.
Request Body
Array of filter conditions to apply. All filters use AND logic. The field name to filter on. Supported fields:
currency
ledger_id
identity_id
indicator
created_at
balance
credit_balance
debit_balance
The comparison operator to use. Operators:
eq: Equals
neq: Not equals
gt: Greater than
gte: Greater than or equal to
lt: Less than
lte: Less than or equal to
in: In list (use with values)
like: Pattern matching
The value to compare against (for single-value operators).
Array of values to match against (for in operator).
Maximum number of results to return.
Number of results to skip for pagination.
Field to sort results by. Example: created_at, balance, currency
Sort direction. Options:
asc: Ascending order
desc: Descending order
Include total count of matching records in response.
Response
Without Count
Returns an array of balance objects matching the filters.
Array of balance objects.
With Count
When include_count: true, returns an object with data and count.
Array of balance objects matching the filters.
Total number of balances matching the filter criteria (before pagination).
Examples
Filter by Currency
Multiple Ledgers
Date Range with Count
Balance Amount Filter
Complex Filters
{
"filters" : [
{
"field" : "currency" ,
"operator" : "eq" ,
"value" : "USD"
}
],
"limit" : 50 ,
"offset" : 0
}
cURL Examples
Basic Filter
With Count
Sorted Results
curl -X POST https://api.blnk.io/balances/filter \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"filters": [
{"field": "currency", "operator": "eq", "value": "USD"}
],
"limit": 50
}'
Response Examples
[
{
"balance_id" : "bal_123abc" ,
"ledger_id" : "ldg_456def" ,
"currency" : "USD" ,
"balance" : "50000" ,
"credit_balance" : "100000" ,
"debit_balance" : "50000" ,
"created_at" : "2024-01-15T10:30:00Z"
},
{
"balance_id" : "bal_456def" ,
"ledger_id" : "ldg_456def" ,
"currency" : "USD" ,
"balance" : "75000" ,
"credit_balance" : "150000" ,
"debit_balance" : "75000" ,
"created_at" : "2024-01-16T14:20:00Z"
}
]
{
"data" : [
{
"balance_id" : "bal_123abc" ,
"ledger_id" : "ldg_456def" ,
"currency" : "USD" ,
"balance" : "50000"
}
],
"total_count" : 1247
}
Use Cases
Find High-Value Balances
Identify balances above a certain threshold:
{
"filters" : [
{
"field" : "balance" ,
"operator" : "gte" ,
"value" : "1000000"
}
],
"sort_by" : "balance" ,
"sort_order" : "desc" ,
"limit" : 100
}
Multi-Currency Reporting
Get balances for specific currencies:
{
"filters" : [
{
"field" : "currency" ,
"operator" : "in" ,
"values" : [ "USD" , "EUR" , "GBP" ]
}
],
"include_count" : true
}
Ledger-Specific Analysis
Analyze balances within specific ledgers:
{
"filters" : [
{
"field" : "ledger_id" ,
"operator" : "eq" ,
"value" : "ldg_customer_accounts"
},
{
"field" : "balance" ,
"operator" : "gt" ,
"value" : "0"
}
],
"sort_by" : "balance" ,
"sort_order" : "desc"
}
Recent Balances
Find recently created balances:
{
"filters" : [
{
"field" : "created_at" ,
"operator" : "gte" ,
"value" : "2024-03-01T00:00:00Z"
}
],
"sort_by" : "created_at" ,
"sort_order" : "desc" ,
"limit" : 50
}
Zero Balance Accounts
Find balances with zero or negative balance:
{
"filters" : [
{
"field" : "balance" ,
"operator" : "lte" ,
"value" : "0"
}
],
"include_count" : true
}
Filter Operators
Equality Operators
// Exact match
{ "field" : "currency" , "operator" : "eq" , "value" : "USD" }
// Not equal
{ "field" : "currency" , "operator" : "neq" , "value" : "USD" }
Comparison Operators
// Greater than
{ "field" : "balance" , "operator" : "gt" , "value" : "100000" }
// Greater than or equal
{ "field" : "balance" , "operator" : "gte" , "value" : "100000" }
// Less than
{ "field" : "balance" , "operator" : "lt" , "value" : "100000" }
// Less than or equal
{ "field" : "balance" , "operator" : "lte" , "value" : "100000" }
List Operators
// In list
{
"field" : "ledger_id" ,
"operator" : "in" ,
"values" : [ "ldg_123" , "ldg_456" , "ldg_789" ]
}
Pattern Matching
// Like (pattern matching)
{ "field" : "indicator" , "operator" : "like" , "value" : "%@example.com" }
Handle large result sets with pagination:
// Page 1
{
"filters" : [ ... ],
"limit" : 100 ,
"offset" : 0 ,
"include_count" : true
}
// Page 2
{
"filters" : [ ... ],
"limit" : 100 ,
"offset" : 100
}
// Page 3
{
"filters" : [ ... ],
"limit" : 100 ,
"offset" : 200
}
Use total_count from the first request to calculate total pages:
const totalPages = Math . ceil ( total_count / limit );
Sorting
Sort results by any field:
// Sort by balance (highest first)
{
"sort_by" : "balance" ,
"sort_order" : "desc"
}
// Sort by creation date (newest first)
{
"sort_by" : "created_at" ,
"sort_order" : "desc"
}
// Sort by currency (alphabetical)
{
"sort_by" : "currency" ,
"sort_order" : "asc"
}
Indexed Fields : Filters on currency, ledger_id, and created_at are optimized
Balance Filters : Filtering by balance amounts may be slower on large datasets
Limit Results : Use reasonable limit values (100-1000) for best performance
Count Queries : include_count: true adds overhead, use only when needed
Pagination : Use offset-based pagination for consistent results
Error Responses
{
"error" : "invalid filter field: invalid_field"
}
{
"error" : "invalid operator: invalid_op"
}
{
"errors" : [ "filters is required" ]
}