ReferenceFor engineers

Pagination

How list queries in the Awell Orchestration API page and sort results using count, offset, and sorting parameters.

List queries return results in pages. You control the page with pagination parameters and the order with sorting parameters, and the response tells you how many results exist in total so you can page through them.

Pagination parameters

List queries accept a pagination argument of type PaginationParams:

FieldTypeDescription
countInt!The number of results to return (page size).
offsetInt!The number of results to skip before this page.

Pagination is offset-based: request the first page with offset: 0, the second with offset: count, and so on.

Two limits worth knowing before you build a loop:

  • Omitting pagination does not return everything. A list query with no pagination argument returns the first 10 results.
  • count is capped at 100. A larger value does not error. The query succeeds and returns 100 records, so code that asks for 500 and trusts the number it asked for misses data with nothing in the response to say so. Page instead: compare offset + count against total_count.

Sorting parameters

List queries also accept a sorting argument of type SortingParams:

FieldTypeDescription
fieldString!The field to sort by.
directionString!"ASC" or "DESC".

direction is a string, not an enum, and the values are uppercase. "asc" is not the same thing as "ASC".

Which fields you can sort by depends on the query, and nested fields are not sortable. For patients, only top-level profile fields work — last_name, birth_date, sex, patient_code and the like — while something like address.city is not supported. patients sorts by last_name ascending when you don't pass a sorting argument.

Reading the response

List responses include a pagination object of type PaginationOutput:

FieldTypeDescription
countIntThe number of results in this page.
offsetIntThe offset this page started at.
total_countIntThe total number of results available.

Keep increasing offset by your page size until offset + count reaches total_count.

Example

query PatientsPage($pagination: PaginationParams, $sorting: SortingParams) {
  patients(pagination: $pagination, sorting: $sorting) {
    patients {
      id
    }
    pagination {
      count
      offset
      total_count
    }
  }
}

Variables:

{
  "pagination": { "count": 25, "offset": 0 },
  "sorting": { "field": "last_name", "direction": "ASC" }
}

On this page