Ir al contenido

Paginación

Todo endpoint de lista devuelve una página a la vez:

{
"data": [
{ "id": "01a1412b-ae38-7c39-8c71-16d2b5dfc472", "type": "invoice", "status": "authorized", "...": "..." },
{ "id": "01a14116-1c50-73e7-8aab-349c93e541da", "type": "invoice", "status": "authorized", "...": "..." }
],
"pagination": { "nextCursor": "MDFhMTQxMTYtMWM1MC03M2U3LThhYWItMzQ5YzkzZTU0MWRh", "hasMore": true }
}
  • limit fija el tamaño de la página: de 1 a 100, 20 por defecto.
  • Cuando hasMore es true, pide la página siguiente con cursor igual a nextCursor. En la última página hasMore es false y nextCursor es null.
  • El cursor es opaco: envíalo exactamente como lo recibiste, junto con los mismos filtros. Un cursor no válido recibe 422 validation_failed con el error de campo invalid_format en cursor.
  • Los recursos individuales (GET /v1/documents/{id}) se devuelven tal cual, sin este envoltorio.
Ventana de terminal
curl "https://api.flashpi.com.ec/v1/documents?status=authorized&limit=100&cursor=MDFhMTQxMTYtMWM1MC03M2U3LThhYWItMzQ5YzkzZTU0MWRh" \
-H "Authorization: Bearer $FLASHPI_API_KEY"
Lista Orden Filtros
GET /v1/documents Del más nuevo al más antiguo issuerId, type, status, issueDateFrom, issueDateTo, counterpartyId, accessKey
GET /v1/events Del más nuevo al más antiguo type, issuerId, documentId, certificateId
GET /v1/issuers Del más nuevo al más antiguo
GET /v1/issuers/{issuerId}/certificates Del más nuevo al más antiguo
GET /v1/webhook-endpoints Del más nuevo al más antiguo
GET /v1/webhook-endpoints/{endpointId}/deliveries Del más nuevo al más antiguo status, eventType, eventId
GET /v1/issuers/{issuerId}/establishments Por código
GET .../establishments/{establishmentId}/emission-points Por código

“Del más nuevo al más antiguo” es por fecha de creación: todo ID es un UUIDv7, que empieza con su fecha de creación. Los elementos creados mientras recorres una lista ordenada así aparecen antes de la primera página, así que nunca desplazan las páginas que estás leyendo.

type Page<T> = { data: T[]; pagination: { nextCursor: string | null; hasMore: boolean } }
export async function* listDocuments(apiKey: string, filters: Record<string, string> = {}) {
let cursor: string | null = null
do {
const query = new URLSearchParams({ ...filters, limit: '100' })
if (cursor) query.set('cursor', cursor)
const response = await fetch(`https://api.flashpi.com.ec/v1/documents?${query}`, {
headers: { Authorization: `Bearer ${apiKey}` },
})
if (!response.ok) throw new Error(`Flashpi answered ${response.status}`)
const page = (await response.json()) as Page<{ id: string; status: string }>
yield* page.data
cursor = page.pagination.hasMore ? page.pagination.nextCursor : null
} while (cursor)
}
for await (const document of listDocuments(process.env.FLASHPI_API_KEY ?? '', { status: 'failed' })) {
console.log(document.id, document.status)
}