def list_all(
*,
limit: int | None = None,
offset: int | None = None,
search: str | None = None,
sort_by: str | None = None,
timeout: float | None = None,
) -> list[RoleResource]async def list_all(
*,
limit: int | None = None,
offset: int | None = None,
search: str | None = None,
sort_by: str | None = None,
timeout: float | None = None,
) -> list[RoleResource]Walks every page and returns the flattened list. Because a workspace is capped at 25 custom roles, this is a single request in practice and is the convenient way to build a name to id map before inviting members.
The trap is limit=: it sets the page size used while walking, not a cap on how many roles come back. Asking for a limit of 5 still returns every role, in more round trips. System roles lead the list, so do not rely on index position to find a custom role.
Example
from envless import envless
roles = envless.roles.list_all()
viewer = next(
(role for role in roles if role['systemKey'] == 'viewer'),
None,
)
print(viewer['id'] if viewer else None)import asyncio
from envless import AsyncEnvless
async def main() -> None:
async with AsyncEnvless() as envless:
roles = await envless.roles.list_all()
viewer = next(
(role for role in roles if role['systemKey'] == 'viewer'),
None,
)
print(viewer['id'] if viewer else None)
asyncio.run(main())Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
limit | int | No | Page size used while walking, clamped to 100. |
offset | int | No | Row to start the walk from. |
search | str | No | Case insensitive substring match against role name and description. |
sort_by | str | No | Order within each group: name (the default) is A to Z, updated and created are newest first. System roles always come first. |
timeout | float | No | Seconds each attempt of this call may take, the response body included, before it raises EnvlessNetworkError with is_timeout set. Overrides the client's timeout for this call, and 0 turns the limit off. |
Returns
list[RoleResource] holding every role in the workspace, system roles first.
Reads the roles collection. list returns one page as a dict with items and pagination, list_all collects every page into a list, and iterate yields one item at a time, fetching the next page only when the loop reaches it. On AsyncEnvless, iterate is an async iterator for async for.
Worth knowing
- Page size defaults to the API maximum of 100 and is clamped there, so a larger limit buys nothing.
- Match system roles on
systemKey, which isowner,adminorviewer, rather than onname, since names are display text.
Required scopes
roles:read
Underlying endpoint
GET /roles
Request and response schema, every error code, and a live playground.
In TypeScript
envless.roles.listAll()
The same method in @goenvless/sdk, with the same request, retries and errors.