Many top-level resources have support for bulk fetches via list API methods. For instance, you can list connections, list directory users, and list directory groups. These list API methods share a common structure, taking at least these four parameters: limit, order, after, and before.
WorkOS utilizes pagination via the after and before parameters. Both parameters take an existing object ID value and return objects in either descending or ascending order by creation time.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); let list = await workos.sso.listConnections({ limit: 100, order: 'desc' }); let connections = list.data; let after = list.listMetadata.after; while (after) { list = await workos.sso.listConnections({ limit: 100, after: after, order: 'desc', }); connections = connections.concat(list.data); after = list.listMetadata.after; }
Parameters