Skip to main content

Pagination

By default, all index (i.e., GET /resources) calls to our API will be paginated. To paginate the API, you can use the limit and offset query parameters.

Basic pagination

This would return page 3 with 20 records per page (records 41-60).

Default behavior

  • Default limit: 20 records
  • Maximum limit: 100 records
  • Default offset: 0
  • Default order: ['createdAt', 'DESC'] (newest first)

Pagination response

Paginated responses include metadata to help with navigation:

Query parameters

Ordering

You can customize the sort order using the order parameter:
Supported directions:
  • ASC - Ascending order
  • DESC - Descending order

Filtering

Use the filter parameter to restrict results:
Depending on your HTTP client, you may need to URL encode the JSON filter object.

Scopes

The Perch API uses scopes to simplify common or complicated queries:
Common scopes:
  • withDeleted - Include soft-deleted records
  • active - Only active (non-deleted) records
Not all scopes are available for each resource. Check the specific endpoint documentation for supported scopes.
Use the include parameter to join related resources:
This reduces the number of API calls needed to get complete data.

Soft deletion

Many resources in our system support soft-deletion, which we call “paranoid” resources. This means that records will not be removed from the database, but instead get a timestamp value set to the record’s deletedAt column.

Working with soft-deleted records

By default, deleted records are not returned:
To include deleted records, use the withDeleted scope:

Lead conversion and soft deletion

When a lead converts to a client profile:
  1. The convertedAt timestamp is set
  2. The deletedAt timestamp is set (automatically archived)
  3. Any associated plans are created and linked
To track converted leads, always use the withDeleted scope:

Best practices

  1. Use appropriate page sizes - Start with the default (20) and adjust based on your needs
  2. Implement client-side caching - Cache results to reduce API calls
  3. Use filters efficiently - Filter on the server side rather than fetching all records
  4. Include related data when needed - Use include to reduce round trips
  5. Handle large datasets - Use pagination rather than trying to fetch all records at once
  6. Combine parameters effectively - Use filtering, ordering, and pagination together

Advanced pagination patterns

Cursor-based pagination alternative

While Perch uses offset-based pagination, you can simulate cursor-based pagination using ordering and filtering:

Efficient lead fetching example

Working with large datasets