QHR Developers

Create a custom role

POST/roles
Needs a read & write tokenCreate roles role/createRequires feature roleNot available in Clauderoles.create

Creates a custom role with an English and an Arabic name (each unique in the company), a role_type and its permissions. The role is active unless is_active is false.

permissions must list every permission of every group available to the role type, each true or false; a missing or unknown key is refused with 422. Take the full list from roles.meta_data for that type and switch on what the role should allow. The type caps what the role can ever hold: an employee role only has self-service groups, a manager role adds team groups, an admin role adds company-wide administration.

When to use: when none of the existing roles fits a group of people, e.g. a payroll clerk who may see salaries but not edit employees.

Prerequisites: the permission keys, from roles.meta_data. Check roles.list first to avoid a name that already exists.

Side effects: recorded in the audit log. Nobody holds the new role until it is given to a user (when inviting them or changing their role). Not offered to Claude: a role defines access to the company's data, which an admin should set deliberately.

Not available in Claude yet.

Before you call this

You will need ids that come from these operations:

Parameters

NameInTypeDescriptionExample
Accept-LanguageheaderstringLanguage of messages and translated labels. English when omitted.
Allowed values: ar, en
ar

Request body

application/json

FieldTypeDescription
roleRequiredobjectThe role's fields.
role.name_enstringName in English, unique in the company.
role.name_arstringName in Arabic, unique in the company.
role.role_typestringThe role's tier: admin (company-wide administration), manager (own team) or employee (self-service). It decides which permission groups the role can hold.
Allowed values: employee, manager, admin
role.is_activebooleanWhether the role can be given to users. Defaults to true.
role.permissionsobjectPermissions as { group_key: { permission_key: true|false } }, using the keys from roles.meta_data. Keys outside the role type's groups are refused.

Response

201 The new role.

FieldTypeDescription
roleRequiredobjectA role with every permission it can hold and whether each one is on.
role.idRequiredintegerRole id.
role.name_enRequiredstringName in English.
role.name_arRequiredstringName in Arabic.
role.nameRequiredstringName in the requested language.
role.is_activeRequiredbooleanWhether the role can still be given to users.
role.is_defaultRequiredbooleanA built-in role (cannot be renamed, deactivated, retyped or deleted).
role.role_typeRequiredstringThe role's tier: admin (company-wide administration), manager (own team) or employee (self-service). It decides which permission groups the role can hold.
Allowed values: employee, manager, admin
role.users_countRequiredintegerActive users who hold the role.
role.permission_groupsRequiredarray<object>Every permission group available to the role's type.
role.permission_groups[].keyRequiredstringGroup key, e.g. leave_request. Used in permissions and permission_groups bodies.
role.permission_groups[].nameRequiredstringGroup name in the requested language.
role.permission_groups[].permissionsRequiredarray<object>The permissions in the group.
role.permission_groups[].permissions[].keyRequiredstringPermission key, e.g. approve.
role.permission_groups[].permissions[].nameRequiredstringWhat the permission allows, in the requested language.
role.permission_groups[].permissions[].hintstringExtra explanation, when there is one.
role.permission_groups[].permissions[].enabledRequiredbooleanWhether the role grants it.
role.role_typesRequiredarray<object>The three role types, for a picker.
role.role_types[].valueRequiredstringRole type key.
role.role_types[].labelRequiredstringRole type name in the requested language.

Errors

HTTPCodeMeaningHow to fix
400bad_requestA parameter is missing or malformed.Check the parameters against this operation's documentation.
401token_missingNo Authorization: Bearer … header, or it is malformed.Send Authorization: Bearer qhr_… with the full token.
401token_invalidThe token is unknown or wrong, or its owner's account is locked.Check the token was copied in full, or create a new one in QHR › Settings › API & Integrations.
401token_expiredThe token is past its expiry date.Create a new token.
401token_revokedThe token was revoked by its owner or an admin, or the owner was removed from the company (which revokes all their tokens).Create a new token, or ask your admin. If the owner was removed, they must be re-invited to the company first.
401tenant_inactiveThe company account is suspended.Contact QHR support.
403token_read_onlyThis token can only read; the operation makes changes.Use a token created with "Allow changes".
403forbiddenThe token owner's role lacks the permission this operation needs.Ask an admin to grant the permission shown on this operation (x-permission).
403employee_inactiveThe token owner's employee record is not active.HR must reactivate the employee record.
403tenant_access_revokedThe token's owner is no longer an active member of this company. Rare: removing a member normally revokes their tokens, which answers 401 token_revoked instead.The owner must be re-invited to the company, then create a new token. If the owner is still a member, contact QHR support.
422validation_failedA permission is missing or unknown for the role type, or a name is missing or already used by another role. error names the first problem (all permission problems at once).Send every permission key from roles.meta_data for that role_type, and two names no other role uses.
This endpoint can also return the errors that can happen on any endpoint →402 / 412 / 425 entitlement_blocked · 429 rate_limited · 500 internal_error

See the full error catalogue →