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.
curl https://api.workos.com/connections?limit=100 \ --header "Authorization: Bearer sk_example_123456789"
{ "data": [ { "object": "connection", "id": "conn_01E4ZCR3C56J083X43JQXF3JK5", "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", "connection_type": "GoogleOAuth", "name": "Foo Corp", "state": "active", "created_at": "2021-06-25T19:07:33.155Z", "updated_at": "2021-06-25T19:08:33.155Z" }, { "object": "connection", "id": "conn_01E2NPPCT7XQ2MVVYDHWGK1WN4", "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", "connection_type": "OktaSAML", "name": "Example Co", "state": "active", "created_at": "2021-06-25T19:09:33.155Z", "updated_at": "2021-06-25T19:10:33.155Z" } ], "list_metadata": { "before": "conn_01E2NPPCT7XQ2MVVYDHWGK1WN4", "after": null } }
| curl https://api.workos.com/connections?limit=100 \ | |
| --header "Authorization: Bearer sk_example_123456789" |
| 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; | |
| } |
| require "workos" | |
| WorkOS.configure do |config| | |
| config.key = "sk_example_12345678" | |
| end | |
| list = WorkOS::SSO.list_connections(limit: 100, order: "desc") | |
| connections = connections.data | |
| after = connections.list_metadata["after"] | |
| until after.nil? | |
| current_page = WorkOS::SSO.list_connections(after: after, limit: 100, order: "desc") | |
| connections = connections.concat(current_page.data) | |
| after = current_page.list_metadata["after"] | |
| end |
| from workos import WorkOSClient | |
| workos_client = WorkOSClient( | |
| api_key="sk_example_123456789", client_id="client_123456789" | |
| ) | |
| all_connections = [] | |
| for connection in workos_client.sso.list_connections(limit=100, order="desc"): | |
| all_connections.append(connection) |
| package main | |
| import ( | |
| "context" | |
| "github.com/workos/workos-go/v3/pkg/sso" | |
| ) | |
| func main() { | |
| sso.Configure( | |
| "sk_example_123456789", | |
| "client_123456789", | |
| ) | |
| list, err := sso.ListConnections( | |
| context.Background(), | |
| sso.ListConnectionsOpts{Limit: 100, Order: "desc"}, | |
| ) | |
| connections := list.Data | |
| after := list.ListMetadata.After | |
| for len(after) > 0 { | |
| currentPage, err := sso.ListConnections( | |
| context.Background(), | |
| sso.ListConnectionsOpts{Limit: 100, Order: "desc", After: after}, | |
| ) | |
| if err != nil { | |
| // Handle the error... | |
| return | |
| } | |
| connections = append(connections, currentPage.Data...) | |
| after = currentPage.ListMetadata.After | |
| } | |
| } |
| <?php | |
| WorkOS\WorkOS::setApiKey("sk_example_123456789"); | |
| $sso = new WorkOS\SSO(); | |
| [$before, $after, $connections] = $sso->listConnections( | |
| limit: 100, | |
| order: "desc" | |
| ); | |
| while ($after) { | |
| [$before, $after, $currentPage] = $sso->listConnections( | |
| limit: 100, | |
| after: $after, | |
| order: "desc" | |
| ); | |
| $connections = array_merge($connections, $currentPage); | |
| } |
| import com.workos.WorkOS; | |
| import com.workos.sso.SsoApi.ListConnectionsOptions; | |
| import com.workos.sso.models.ConnectionList; | |
| import java.util.List; | |
| ListConnectionsOptions options = new ListConnectionsOptions(); | |
| options.put("limit", "100"); | |
| options.put("order", "desc"); | |
| ConnectionList list = workos.sso.listConnections(options); | |
| String after = list.listMetadata.after; | |
| List connections = list.data; | |
| while (after != null) { | |
| options.put("after", after); | |
| ConnectionList currentPage = workos.sso.listConnections(options); | |
| after = currentPage.listMetadata.after; | |
| connections.add(currentPage.data); | |
| } |
| WorkOS.SetApiKey("sk_example_123456789"); | |
| var ssoService = new SSOService(); | |
| List<object> connections = new List<object>(); | |
| var list = await ssoService.ListConnections(Limit = 100, Order = 'desc'); | |
| foreach (object i in list.Data) | |
| { | |
| connections.Add(i); | |
| }; | |
| var after = list.ListMetadata.After; | |
| While(after); | |
| { | |
| list = await ssoService.ListConnections(After = after, Limit = 100, Order = 'desc'); | |
| foreach (object i in list.Data) | |
| { | |
| connections.Add(i); | |
| } | |
| after = list.ListMetadata.After; | |
| }; |
| { | |
| "data": [ | |
| { | |
| "object": "connection", | |
| "id": "conn_01E4ZCR3C56J083X43JQXF3JK5", | |
| "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", | |
| "connection_type": "GoogleOAuth", | |
| "name": "Foo Corp", | |
| "state": "active", | |
| "created_at": "2021-06-25T19:07:33.155Z", | |
| "updated_at": "2021-06-25T19:08:33.155Z" | |
| }, | |
| { | |
| "object": "connection", | |
| "id": "conn_01E2NPPCT7XQ2MVVYDHWGK1WN4", | |
| "organization_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", | |
| "connection_type": "OktaSAML", | |
| "name": "Example Co", | |
| "state": "active", | |
| "created_at": "2021-06-25T19:09:33.155Z", | |
| "updated_at": "2021-06-25T19:10:33.155Z" | |
| } | |
| ], | |
| "list_metadata": { | |
| "before": "conn_01E2NPPCT7XQ2MVVYDHWGK1WN4", | |
| "after": null | |
| } | |
| } |
Parameters