iterate(options?: RoleListOptions): AsyncGenerator<RoleResource, void, undefined>Yields roles individually, fetching the next page only once the current one is drained. Role sets are small, so this exists mainly for symmetry with the other collections and for the ability to stop as soon as you find the row you wanted.
It returns an async generator, not a promise, so do not await the call itself: put it straight into a for await loop. No request is issued until the first iteration, and breaking out of the loop leaves any remaining pages unfetched.
Example
for await (const role of envless.roles.iterate()) {
if (role.isSystem) continue
console.log(role.name, role.permissions.length)
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options.limit | number | No | Page size fetched behind the scenes, clamped to 100. |
options.offset | number | No | Row to start streaming from. |
options.search | string | No | Case insensitive substring match against role name and description. |
options.sortBy | RoleSort | No | Order within each group: name (the default) is A to Z, updated and created are newest first. System roles always come first. |
options.signal | AbortSignal | No | Cancels the in flight page request and ends the stream. |
Returns
An AsyncGenerator that yields RoleResource values until the pages run out.
Reads the roles collection. list returns one page as { items, pagination }, listAll collects every page into an array, and iterate streams one item at a time without buffering the whole set.
Worth knowing
- The offset advances by the number of rows actually received, so a role created mid walk can shift the window.
- System roles are yielded before custom roles, so a loop that breaks on the first row always sees a system role.
Required scopes
roles:read
Underlying endpoint
GET /roles
Request and response schema, every error code, and a live playground.
In Python
envless.roles.iterate()
The same method in envless-sdk, the Python SDK, with the same request, retries and errors.
In Ruby
Envless.roles.iterate
The same method in envless-sdk, the Ruby gem, with the same request, retries and errors.
In PHP
$envless->roles->iterate()
The same method in envless/sdk, the PHP SDK, with the same request, retries and errors.