Skip to content

Pagination ​

Every list endpoint in the OneFive API uses cursor-based pagination. This approach scales to any dataset size and produces stable results even as new records are created between pages.

How it works ​

Each list request returns a pagination object alongside the data array:

json
{
  "data": [...],
  "pagination": {
    "cursor": "eyJ0IjoiMjAyNi0wOC0yNCIsImlkIjoicHJvZF9hYmMxMjMifQ==",
    "has_more": true,
    "total": 142
  }
}
FieldTypeDescription
cursorstring | nullOpaque token to fetch the next page. null on the last page.
has_morebooleanWhether more results exist beyond this page.
totalintegerTotal count of records matching the query filters.

To fetch the next page, pass the cursor value as a query parameter:

bash
curl "https://api.hydrajs.dev/v1/products?cursor=eyJ0IjoiMjAyNi..." \
  -H "Authorization: Bearer sk_your_key"

Page size ​

Use the limit parameter to control how many records are returned per page. The default is 25 and the maximum is 250.

bash
curl "https://api.hydrajs.dev/v1/products?limit=100" \
  -H "Authorization: Bearer sk_your_key"

Sorting ​

Most list endpoints support sort and order parameters:

bash
# Newest first (default)
curl "https://api.hydrajs.dev/v1/products?sort=created_at&order=desc" \
  -H "Authorization: Bearer sk_your_key"

# Alphabetical by title
curl "https://api.hydrajs.dev/v1/products?sort=title&order=asc" \
  -H "Authorization: Bearer sk_your_key"

Available sort fields vary by resource. Check the endpoint reference for each.

Iterating all pages ​

To process every record, loop until has_more is false.

With the SDK ​

typescript
import { createClient } from '@onefive/hydra'

const hydra = createClient({ apiKey: 'sk_...' })

// Async iterator (recommended)
for await (const product of hydra.products.iterate({ limit: 100 })) {
  console.log(product.title)
}

// Or collect everything into an array
const all = await hydra.products.toArray({ limit: 100 })

With fetch ​

typescript
let cursor: string | undefined

do {
  const params = new URLSearchParams({ limit: '100' })
  if (cursor) params.set('cursor', cursor)

  const res = await fetch(`https://api.hydrajs.dev/v1/products?${params}`, {
    headers: { Authorization: `Bearer ${SECRET_KEY}` }
  })
  const { data, pagination } = await res.json()

  for (const product of data) {
    // process each product
  }

  cursor = pagination.has_more ? pagination.cursor : undefined
} while (cursor)

Sparse fieldsets ​

Use the fields parameter to limit which fields are returned. This reduces payload size when you only need a few properties:

bash
curl "https://api.hydrajs.dev/v1/products?fields=id,title,handle,status" \
  -H "Authorization: Bearer sk_your_key"

The id field is always included regardless of the fields parameter. Unknown field names are silently ignored.

Use the expand parameter to inline related resources in the response, avoiding extra API calls:

bash
curl "https://api.hydrajs.dev/v1/products?expand=variants,images" \
  -H "Authorization: Bearer sk_your_key"

Available expansions vary by resource. Check the endpoint reference for supported values.

Cursors are opaque strings. Do not parse, modify, or store them long-term. They may change format between API versions.