Official Libraries
- @unkey/api
- Overview
- Keys
- APIs
- Identities
- Ratelimits
- Migrations
- Permissions
- @unkey/ratelimit
- @unkey/nextjs
- @unkey/hono
- @unkey/cache
- unkey-go
- unkey.py
Community Libraries
- Elixir
- Nuxt
- Rust
- Springboot
Keys
Add Roles
Add one or more roles to a key.
const { result, error } = await unkey.keys.addRoles({
keyId: "key_123",
roles: [{
"name": "domain.manager",
"create": true
}]
})
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
console.log(result)
{
"result": [
{
"id": 'role_45TTRKT5Yh28M6Qj',
"name": 'domain.manager'
}
]
}
const { result, error } = await unkey.keys.addRoles({
keyId: "key_123",
roles: [{
"name": "domain.manager",
"create": true
}]
})
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
console.log(result)
{
"result": [
{
"id": 'role_45TTRKT5Yh28M6Qj',
"name": 'domain.manager'
}
]
}
To use this function, your root key must have the rbac..add_role_to_key and potentially the rbac..create_role permissions.
Request
The id of the key
The roles you want to add to this key
The id of the role. Provide either id or name. If both are provided id is used.
Identify the role via its name. Provide either id or name. If both are provided id is used.
Set to true to automatically create the permissions they do not exist yet. Only works when specifying name. Autocreating roles requires your root key to have the rbac.*.create_role permission, otherwise the request will get rejected
Response
Was this page helpful?
const { result, error } = await unkey.keys.addRoles({
keyId: "key_123",
roles: [{
"name": "domain.manager",
"create": true
}]
})
if (error) {
// handle potential network or bad request error
// a link to our docs will be in the `error.docs` field
console.error(error.message);
return;
}
console.log(result)
{
"result": [
{
"id": 'role_45TTRKT5Yh28M6Qj',
"name": 'domain.manager'
}
]
}
Assistant
Responses are generated using AI and may contain mistakes.