Skip to main content
A custom role is a named set of scopes that an owner or admin of your organization gives to a member. This guide shows how to create roles, change and delete them, and give them to members, with the MKA1 SDKs, the CLI and the HTTP API. For every field and status code, see the Organization section of the API reference.

Before you start

  • Use an owner’s or admin’s API key. Listing, creating, changing and deleting roles, and giving them to members, need the API key of a person who is an owner or admin of the organization. Service account keys are refused for these calls. Listing members and reading your own scopes need only membership of the organization.
  • Give the key the right scopes. The key needs read:org to list roles and members, and write:org to create, change, delete or give a role.
  • Know your organization’s ID. Every request takes it as orgId. The examples use the placeholder <org-id>.
  • Pass the API key on each call. These operations take their credentials as a per-call argument: the first argument in the TypeScript SDK, security in the Python and C# SDKs, and --bearer-auth in the CLI. The CLI examples pass the MKA1_BEARER_AUTH variable from your shell.

Add a role

List roles and supported scopes

Start by listing the organization’s roles. The response holds roles, the organization’s custom roles, and supportedScopes, the scopes a custom role can hold. Choose a role’s scopes from supportedScopes.

Create a role

Create a role with a name and a list of scopes. The name is 1 to 64 characters with no comma, control or invisible character. It must differ from every other role’s name in the organization, ignoring case, and cannot be owner, admin or member. A role may hold no scopes. An organization can have up to 100 custom roles.
The response returns 201 with the new role: its id, name, scopes, createdAt and updatedAt. Keep the role’s id: you use it to change, delete and give the role. The API answers:
  • 409 with ROLE_NAME_TAKEN when another role already has the name.
  • 400 with ROLE_SCOPES_UNSUPPORTED when a scope is not in supportedScopes.
  • 409 with ROLE_LIMIT_REACHED when the organization already has 100 custom roles.

Manage roles

Rename a role or change its scopes

Send a new name, new scopes, or both. scopes replaces the role’s whole set, so send every scope the role should hold. A change applies to every member who holds the role.
The response returns the updated role. The name and scope rules for creating a role apply here too, with one exception: a scope the role already holds is kept even if it is no longer in supportedScopes.

Delete a role

The response returns the role’s id and deleted: true. While a member still holds the role, the API answers 409 with ROLE_IN_USE and keeps the role. Clear the role from each member who holds it, then delete it again.

Give a role to a member

A custom role is given to a member whose organization role is member. A member holds at most one custom role, and keeps the organization role member.

Find the member

List the organization’s members to find the person. Each member has an id, which is the memberId you send when you give a role. It is not the same as userId or user.id.
Each member in the list also carries role, customRoles and scopes. The list returns up to 100 members per call, with the organization’s total. In a larger organization, page through it with limit and offset.

Give, change or clear a member’s role

Send the member’s custom roles as roleIds. The list replaces the roles the member holds:
  • To give a role, send a list with that role’s id.
  • To change it, send a list with the other role’s id.
  • To clear it, send an empty list.
The response returns the member with its role, its customRoles (id and name) and its scopes. The API answers:
  • 409 with CUSTOM_ROLE_REQUIRES_MEMBER when the person is an owner, an admin or a service account. Change their organization role to member first. An empty list is accepted for anyone.
  • 400 with CUSTOM_ROLE_LIMIT when roleIds holds more than one role.
A member who is later made an owner or admin, or who leaves the organization, no longer holds the custom role.

Read a person’s scopes

scopes on each member in the member list is the person’s scopes in the organization. For a member who holds a custom role, it is that role’s scopes. For an owner, an admin, or a member without a custom role, it is what their organization role can put on an API key. A change to a role shows on the next read. To read your own role and scopes, call getMe with your own API key. Any human member of the organization can make this call with a key that has read:org.
The response returns your organizationId, userId, memberId, role, customRoles and scopes.