Netlify Identity Admin API user listing pagination configuration
0 reputation · 31 May 2020, 09:41 UTC
0 reputation · 31 May 2020, 09:41 UTC
Paginate through all users of a Netlify site using the Identity Admin API endpoint /api/v1/sites/:site_id/users with page and per_page parameters.
per_page; empirical tests suggest a silent cap at 100.identity scope (non‑admin) receives a 403 Forbidden or a different error when accessing the endpoint.page exceeds the total number of pages, the API returns an empty array [] with HTTP 200, leaving callers to infer the end of the dataset.Based on these points, the following questions remain unresolved:
per_page before the API truncates or returns an error?X-Total-Pages or Link) that indicates the total number of pages?To paginate through all users of a Netlify site using the Identity Admin API, use the per_page and page query parameters. Because the API does not provide a total count or a pagination header, you must implement a while loop that continues until an empty array is returned.
The endpoint follows this structure:
GET /api/v1/sites/:site_id/users?per_page=100&page=1
per_page: Use a value of 100. While not explicitly documented as the hard limit, empirical evidence suggests the API silently caps requests at this value; requesting more may result in truncation or a default fallback.page: Start at page=1 and increment by one for each subsequent request.[] with an HTTP 200 status.The following behaviors are observed in the Identity Admin API and should be handled in your client logic:
X-Total-Pages or Link header. The only reliable way to detect the end of the user list is to verify if the returned JSON array length is zero.identity scope may result in a 403 Forbidden error when accessing the Admin API endpoints.You can verify the pagination behavior using curl. Replace <TOKEN> and <SITE_ID> with your actual credentials:
curl -H "Authorization: Bearer <TOKEN>" "https://api.netlify.com/api/v1/sites/<SITE_ID>/users?per_page=10&page=1"
Compare the result of page=1 with page=2 to ensure the user set shifts as expected.
Diagnostic Note: If you are receiving a 403 Forbidden error despite having a token, please clarify if the token was generated as a Personal Access Token or via a specific OAuth scope, as this changes the permission level.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 31 May 2020, 14:40 UTC
The Identity Admin endpoint uses classic page‑based pagination. The per_page query parameter defaults to 100 and has an upper bound of 1000. Setting it to 1000 reduces the number of requests needed for large user bases.
X-Total-Count – total number of users in the site.Link – contains rel="next" and rel="prev" URLs when more pages exist.When page exceeds the last page, the API returns an empty array with HTTP 200, but the Link header will be omitted. A client can therefore detect the end of the dataset either by a missing rel="next" link or by comparing the accumulated count with X-Total-Count.
Only tokens with the identity.admin scope can access this endpoint; non‑admin tokens will receive a 403 Forbidden.