Filtering & Sorting
Prahsys APIs provide powerful filtering and sorting capabilities to help you efficiently manage and retrieve data. These features work consistently across our list endpoints, making it easy to find exactly what you need.
Filtering
Prahsys APIs support flexible filtering options to narrow down results based on specific criteria.
Basic Filtering
To filter results, use the filter
parameter in your query string:
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?filter[status]=COMPLETED" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
Multiple Filters
Apply multiple filters by adding additional filter parameters:
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?filter[status]=COMPLETED&filter[amount]=1000" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
Multiple Values for a Single Filter
Use comma-separated values to match multiple possibilities:
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?filter[status]=COMPLETED,PENDING" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
This returns payments with status COMPLETED OR PENDING.
Automatic Type Conversion
The query builder automatically maps certain values:
1
,0
,true
, andfalse
are converted toboolean
values- Comma-separated lists are converted to arrays for IN queries
{merchantId}/payments?filter[active]=true" \ -H "Authorization: Bearer $PRAHSYS_API_KEY" ``` ```bash title="Where In"
/filter[status]=COMPLETED,PENDING,PROCESSING"/ curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}
/payments?filter[status]=COMPLETED,PENDING,PROCESSING" \ -H "Authorization: Bearer $PRAHSYS_API_KEY" ```
</CodeGroup>
### Dynamic Operator Filters
For numeric comparisons, you can use dynamic operators by prefixing the value:
<CodeGroup>
```bash title="Greater than" /filter[salary]=>3000/
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/employees?filter[salary]=>3000" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
Filtering Example
Advanced filtering
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?filter[amount]=>1000&filter[status]=COMPLETED,PENDING" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
Refer to specific API endpoint documentation to see which fields support filtering. Not all fields are filterable on every endpoint.
Sorting
Control the order of returned results using the sort
parameter.
Basic Sorting
All sorting defaults to ascending order.
Basic sort
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?sort=createdAt" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
Descending Order
Prefix the field name with a minus sign (-
) to sort in descending order:
Descending sort
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?sort=-createdAt" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
Multiple Sort Fields
Sort by multiple fields using a comma-separated list:
Multiple sort fields
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?sort=-createdAt,status" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
This example sorts payments by creation date (newest first), and then by status (alphabetically) for records with the same creation date.
Sort Direction
- Ascending order: Use the field name without a prefix (
sort=createdAt
) - Descending order: Add a minus sign before the field name (
sort=-createdAt
)
Refer to specific API endpoint documentation to see which fields support sorting. Not all fields are sortable on every endpoint.
Combining Filtering and Sorting
You can combine filtering and sorting in a single request:
Combined request
curl -X GET "https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?filter[status]=COMPLETED&sort=-amount" \
-H "Authorization: Bearer $PRAHSYS_API_KEY"
This request:
- Includes only payments with a status of “COMPLETED”
- Sorts results by amount in descending order (highest first)
Implementation Examples
// Fetch completed payments, sorted by amount (highest first)
async function fetchPayments() {
const response = await fetch(
"https://api.prahsys.com/payments/n1/merchant/{merchantId}/payments?filter[status]=COMPLETED&sort=-amount",
{
method: "GET",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
}
}
);
const data = await response.json();
return data.data;
}
Best Practices
- Use specific filters to reduce the dataset size
- Combine multiple filters for more precise results
- Sort by indexed fields for better performance on large datasets
- Use filtering before sorting to improve query efficiency
For additional information on specific filterable or sortable fields, refer to the documentation for each API endpoint.