---
title: "Members"
description: "`members.list`, `list_all`, `iterate`, `get`, `add`, `update`, `remove`, `grant_address`, `revoke_address`, and the invitation methods beside them."
url: "https://openemail.uk/docs/ruby/members"
area: "Ruby"
category: "Mailbox"
---

# Members

`members.list`, `list_all`, `iterate`, `get`, `add`, `update`, `remove`, `grant_address`, `revoke_address`, and the invitation methods beside them.

## Every method

**members.rb**

```
support_role_id = "role_8b1f4c2e9a7d3b60e5f1a2c4"
viewer_role_id = "role_2c7e9a1f4b8d3e60c5a7f1b9"

invitation = client.members.add(
  email: "sam@acme.com",
  roleId: support_role_id,
  addressIds: ["2b81de07-9c3f-4a61-b8e2-5d07f4c19a36"],
  access: "member"
)
puts invitation[:id], invitation[:expiresAt]

people = client.members.list_all
puts people.map { |person| "#{person[:email]} #{person[:userId]}" }

sam_id = "q7Vd3kX9mT2pLw8RzN4bYc6HfJ1sGa5E"
member = client.members.get(sam_id)
puts member.dig(:role, :name), member[:implied]

client.members.update(sam_id, roleId: viewer_role_id)

address_id = "c40a95f2-1e7b-4d38-a6c9-82f05b3d7e14"
client.members.grant_address(sam_id, addressId: address_id, access: "viewer")
client.members.revoke_address(sam_id, address_id)

removed = client.members.remove(sam_id)
puts removed[:addressesRevoked]
```

Two grants per person, and they must not be collapsed. `role` is what they may do. `addresses` is what they may do it to. Both have to agree: a role holding `emails:send` with `access: "viewer"` on invoices@ is somebody who may send mail and may not send it from that address. The exception is a role holding `addresses:all`, which reaches every address whatever `addresses` lists, because that Array holds only direct grants. So check `permissions` before reading `addresses` as the whole of somebody’s reach.

Every call about one person takes their `userId` as its first argument, not their email, so read it off `list` or `list_all` as the sample does. `add` is the one exception, because it invites an address: the person has a `userId` only once they accept, and `list_invitations` follows the invitation until then. The fields of a request body keep the API’s camelCase names (`roleId:`, `addressIds:`, `addressId:`), passed as keywords or as one Hash.

`list` returns one `OpenEmail::Page`, `list_all` returns every member in one Array, and `iterate` yields each member to a block or returns an Enumerator without one. A member comes back as a Hash with Symbol keys, and `role` is a Hash inside it, so `member.dig(:role, :name)` reads the role’s name.

> `implied: true` means nobody chose the role. They hold addresses and no role row, so it was inferred from the widest grant they have. Treat it as “not decided yet”, and `update` is what turns the inference into a decision. Until then, widening their address access silently widens what they may do.

> The workspace owner is the first row, marked `isOwner: true`, while `add`, `update` and `remove` still refuse them with `member_is_owner`, a 422 raised as `OpenEmail::ValidationError`. An unshared workspace reports one member rather than none, so exclude `isOwner` when you are counting seats: `client.members.list_all.count { |member| !member[:isOwner] }`.

> `remove` takes both axes, the role AND every address grant on this workspace, and reports `addressesRevoked`. `revoke_address` is the narrow one, for somebody who moved team rather than somebody who left.

## Parameters

- `email` (String, required): Who to invite, trimmed and lower-cased. It does not need an account yet: everybody is invited, and the role and grants land when they accept. Somebody already in the workspace is `member_is_owner` (422).
- `roleId` (String, required): The role they will hold, 1 to 128 characters, and it must be a role on this workspace: an unknown id is `role_not_found` (404), raised as `OpenEmail::NotFoundError`. The owner role cannot be handed out and comes back `role_immutable` (409), because making somebody an owner is a workspace transfer and there is no call for that here.
- `addressIds` (Array<String>): Addresses the invitation carries, at most 64 ids of 1 to 128 characters each, granted when it is accepted. Every id is checked before anything is written, so one that is not an address on this workspace refuses the whole call with 422 `member_not_found` and nothing is sent. Inviting the same address again within ten minutes is 409 `invitation_too_soon`.
- `access` (String): What they may do with every id in `addressIds`: `member` reads the address and sends as it, `viewer` only reads it. Defaults to `member`, the level the console and the older sharing path have always used, so the same call means the same thing from a script and from a screen. Grant a mixture by calling `grant_address` afterwards for the ones that differ.

## Response

- `object` (String): Always `member`. A removal answers with the same value, their `userId`, `deleted: true` and `addressesRevoked`, and none of the other fields below.
- `userId` (String): Their account id, and the handle every other member call takes as its first argument: `get`, `update`, `remove` and both address calls. Adding somebody is the one call that works from an email instead, because whoever is adding a colleague knows their address and not their id.
- `email` (String): The email on their account, echoed as that row stores it. This resource never writes it, and the lower-casing on `add` applies to the address you send for the lookup rather than to what comes back. After the owner, the members list is sorted by it rather than by when people joined, because the list is read to find one person rather than to see what changed.
- `name` (String or nil): Their display name, taken from their account, where the column always holds a value. The nil in the type is defensive rather than a state this API has been seen to produce. It belongs to them rather than to the workspace, so nothing on this resource can set it.
- `image` (String or nil): Their avatar, taken from their account, and nil when they have not set one.
- `role.id` (String or nil): The id of the role they hold, read as `member.dig(:role, :id)`, or nil when nobody chose it. See `implied`. A nil here is the one case where `role` reports an inference rather than a decision somebody made.
- `role.name` (String): The role’s name. For an implied member it is the name of the built-in template their access maps to, not a row on this workspace.
- `role.builtin` (String or nil): Which built-in the role is, `owner`, `admin`, `member`, `viewer`, `developer` or `billing`, or nil for a custom one. `owner` appears only on the owner’s own row, alongside `isOwner: true`. Assigning that role to anybody is refused with `role_immutable` (409).
- `isOwner` (Boolean): True on exactly one row, the account the workspace is keyed on. They hold every permission whatever their role row says, they sort first, and `add`, `update` and `remove` all refuse them with `member_is_owner`. Exclude them when you are counting seats.
- `implied` (Boolean): True when this person has address grants and no member row, so their role was inferred rather than chosen: any grant of `member` makes it the built-in Member, otherwise Viewer. Never true for the owner. Show it as "implied by access". Until an `update` turns the inference into a decision, widening their address access silently widens what they may do.
- `permissions` (Array<String>): The role’s permissions flattened onto the member, so one read answers "may they?" without fetching the role. For an implied member they come from the built-in TEMPLATE rather than from this workspace’s role row, so editing the built-in Member role does not change what an implied member holds.
- `addresses` (Array<Hash>): The addresses they have been given, sorted by address, each with its own access level. Empty for somebody holding a role and no grants, which is what a new member looks like until an address is granted, and is the right failure to have while you are still deciding what they should see.
- `addresses[].addressId` (String): The id of the address, and what `grant_address` and `revoke_address` take. An id that is not an address on this workspace is refused on both, rather than reporting a revocation that never happened.
- `addresses[].address` (String): The full address, lower-cased, rebuilt from its local part and its domain.
- `addresses[].access` (String): What they may do with this one address: `member` reads it and sends as it, `viewer` only reads it. This and the role both have to allow a send before one happens, so a role holding `emails:send` over a `viewer` grant sends from nothing. The stored column is called `role`, and it is renamed here so one Hash does not carry two `role` keys drawn from two vocabularies.
- `createdAt` (String or nil): When their member row was written, as an ISO 8601 String, and nil when there is no member row at all. That nil describes the same population as `implied: true`: people who hold addresses from before roles existed and whom nobody has since given a role.

## Invitations

**invitations.rb**

```
waiting = client.members.list_all_invitations

waiting.each do |invitation|
  client.members.resend_invitation(invitation[:id]) if invitation[:expired]
end

client.members.revoke_invitation("winv_6bb640f5b99e47deb758f1f5")
```

`add` answers with an invitation, and these are the calls that follow one up. `list_invitations` returns one `OpenEmail::Page` of the ones nobody has accepted yet, `list_all_invitations` returns all of them in one Array, and `iterate_invitations` yields each one to a block or returns an Enumerator. `resend_invitation` sends one again with a new link and fourteen more days, and `revoke_invitation` withdraws it. A waiting invitation grants nothing until it is accepted.

> `resend_invitation` refuses the same address twice within ten minutes with 409 `invitation_too_soon`, and `revoke_invitation` refuses one that was accepted first with 409 `invitation_accepted`. Both are raised as `OpenEmail::ConflictError`, so `conflict?` is true and `code` tells them apart.
