Roles

Envless.roles.list_all

Collect every role in the workspace into one array

def list_all(
  limit: nil,
  offset: nil,
  search: nil,
  sort_by: nil,
  timeout: nil
)

Walks every page and returns the flattened array. 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 array, so do not rely on index position to find a custom role.

Example

ruby
require "envless/sdk"

roles = Envless.roles.list_all

viewer = roles.find { |role| role[:systemKey] == "viewer" }

puts viewer&.fetch(:id)

Parameters

ParameterTypeRequiredDescription
limit:IntegerNoPage size used while walking, clamped to 100.
offset:IntegerNoRow to start the walk from.
search:String | SymbolNoCase insensitive substring match against role name and description.
sort_by:"updated" | "created" | "name"NoOrder within each group: name (the default) is A to Z, updated and created are newest first. System roles always come first.
timeout:Integer | Float | RationalNoSeconds each attempt of this call may take, redirects and the response body included, before it raises Envless::NetworkError with timeout? set. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

Array[role_resource] holding every role in the workspace, system roles first.

Reads the roles collection. list returns one page as an Envless::Page with items and pagination, list_all collects every page into an array, and iterate yields one item at a time to a block, fetching the next page only when it gets there. Without a block, iterate returns an Enumerator.

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 is owner, admin or viewer, rather than on name, 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.