Advanced Querying
The Flow API supports advanced filtering and querying across all list endpoints. This guide covers the query syntax and available operators.
Filter Syntax
Filters use the filter[field] or filter[field][operator] syntax:
GET /v1/posts?filter[status]=queued
GET /v1/posts?filter[status][ne]=done
GET /v1/posts?filter[scheduledFor][gte]=1703123456000
Supported Operators
| Operator | Description | Example |
|---|---|---|
eq | Equals (default) | ?filter[status]=queued |
ne | Not equals | ?filter[status][ne]=done |
gt | Greater than | ?filter[scheduledFor][gt]=1703123456000 |
gte | Greater than or equal | ?filter[scheduledFor][gte]=1703123456000 |
lt | Less than | ?filter[scheduledFor][lt]=1703123456000 |
lte | Less than or equal | ?filter[scheduledFor][lte]=1703123456000 |
in | In array | ?filter[channelId][in]=id1,id2,id3 |
contains | String contains | ?filter[content][contains]=hello |
Examples
Posts
# Get all queued posts
GET /v1/posts?filter[status]=queued
# Get posts scheduled after a date
GET /v1/posts?filter[scheduledFor][gte]=1703123456000
# Get posts from specific channels
GET /v1/posts?filter[channelId][in]=channel1,channel2,channel3
# Get posts containing specific text
GET /v1/posts?filter[content][contains]=announcement
# Combine multiple filters
GET /v1/posts?filter[status]=queued&filter[channelId]=channel123&filter[scheduledFor][gte]=1703123456000
Channels
# Get channels created after a date
GET /v1/channels?filter[createdAt][gte]=1703123456000
# Get channels with specific name
GET /v1/channels?filter[name][contains]=marketing
Combining Filters
Multiple filters are combined with AND logic:
GET /v1/posts?filter[status]=queued&filter[channelId]=channel123
This returns posts that are:
- Status equals "queued" AND
- Channel ID equals "channel123"
Date/Time Filtering
For timestamp fields (scheduledFor, createdAt), you can use:
- Unix timestamp (milliseconds):
?filter[scheduledFor][gte]=1703123456000 - ISO 8601 string:
?filter[scheduledFor][gte]=2024-12-25T10:00:00Z
Both formats are automatically parsed.
Array Filtering (IN)
Use the in operator to match multiple values:
GET /v1/posts?filter[channelId][in]=channel1,channel2,channel3
Values are comma-separated. Empty values are ignored.
String Contains
Use the contains operator for partial string matching:
GET /v1/posts?filter[content][contains]=announcement
This matches posts where the content contains "announcement" (case-sensitive in SQLite).
Sorting
Combine filtering with sorting:
GET /v1/posts?filter[status]=queued&sort=-scheduledFor
Sort syntax:
sort=field- Ascendingsort=-field- Descending
Available sort fields:
scheduledFor(default)createdAtstatus
Pagination
Filters work with pagination:
GET /v1/posts?filter[status]=queued&page=1&per_page=20
Field Reference
Posts
| Field | Type | Operators |
|---|---|---|
status | string | eq, ne, in |
channelId | string | eq, ne, in |
scheduledFor | number (timestamp) | eq, ne, gt, gte, lt, lte |
createdAt | number (timestamp) | eq, ne, gt, gte, lt, lte |
content | string | contains |
Channels
| Field | Type | Operators |
|---|---|---|
name | string | contains |
createdAt | number (timestamp) | eq, ne, gt, gte, lt, lte |
Limitations
- Case sensitivity: String comparisons are case-sensitive (SQLite limitation)
- Performance: Complex filters may be slower on large datasets
- Field support: Not all fields support all operators (see field reference above)
Best Practices
- Use specific filters - Narrow down results before pagination
- Combine with pagination - Always paginate large result sets
- Index fields - Filter on indexed fields for better performance
- Limit filter complexity - Too many filters can slow down queries
SDK Support
The Flow SDKs support filtering:
TypeScript SDK
// Filtering is built into list methods
const posts = await flow.posts.list({
status: 'queued',
channelId: 'channel_123',
});
Python SDK
# Filtering via query parameters
posts = flow.posts.list(
status='queued',
channel_id='channel_123'
)
Examples
Get posts scheduled for today
# Get current timestamp
NOW=$(date +%s)000 # Convert to milliseconds
TODAY_START=$((NOW - (NOW % 86400000))) # Start of day
TODAY_END=$((TODAY_START + 86400000)) # End of day
GET /v1/posts?filter[scheduledFor][gte]=${TODAY_START}&filter[scheduledFor][lt]=${TODAY_END}
Get posts from multiple channels
GET /v1/posts?filter[channelId][in]=channel1,channel2,channel3
Get queued posts scheduled in the future
NOW=$(date +%s)000
GET /v1/posts?filter[status]=queued&filter[scheduledFor][gt]=${NOW}
Support
- Documentation: https://docs.flowsocial.app
- Support: https://flowsocial.app/support