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:orgto list roles and members, andwrite:orgto 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,
securityin the Python and C# SDKs, and--bearer-authin the CLI. The CLI examples pass theMKA1_BEARER_AUTHvariable from your shell.
Add a role
List roles and supported scopes
Start by listing the organization’s roles. The response holdsroles, 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 aname 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.
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:
409withROLE_NAME_TAKENwhen another role already has the name.400withROLE_SCOPES_UNSUPPORTEDwhen a scope is not insupportedScopes.409withROLE_LIMIT_REACHEDwhen the organization already has 100 custom roles.
Manage roles
Rename a role or change its scopes
Send a newname, 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.
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
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 ismember.
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 anid, which is the memberId you send when you give a role.
It is not the same as userId or user.id.
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 asroleIds.
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.
member with its role, its customRoles (id and name) and its scopes.
The API answers:
409withCUSTOM_ROLE_REQUIRES_MEMBERwhen the person is an owner, an admin or a service account. Change their organization role tomemberfirst. An empty list is accepted for anyone.400withCUSTOM_ROLE_LIMITwhenroleIdsholds more than one 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.
organizationId, userId, memberId, role, customRoles and scopes.
Related guides
- Teams and members for the organization’s built-in roles: owner, admin and member.
- Authentication for API keys and their scopes.