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 Permissions
Add one or more permissions to a key.
Copy
const { result, error } = await unkey.keys.addPermissions({
keyId: "key_123",
permissions: [{
"name": "email.test",
"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)
Copy
{
"result": [
{
"id": 'perm_45TTRKT5Yh28M6Qj',
"name": 'email.test'
}
]
}
Copy
const { result, error } = await unkey.keys.addPermissions({
keyId: "key_123",
permissions: [{
"name": "email.test",
"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)
Copy
{
"result": [
{
"id": 'perm_45TTRKT5Yh28M6Qj',
"name": 'email.test'
}
]
}
To use this function, your root key must have the rbac.*.add_permission_to_key
and the rbac.*.create_permission
permissions if you plan on creating permissions on the fly.
Request
The id of the key
The permissions you want to add to this key
The id of the permission. Provide either id or name. If both are provided id is used.
Identify the permission 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 permissions requires your root key to have the rbac.*.create_permission permission, otherwise the request will get rejected
Response
Was this page helpful?
Copy
const { result, error } = await unkey.keys.addPermissions({
keyId: "key_123",
permissions: [{
"name": "email.test",
"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)
Copy
{
"result": [
{
"id": 'perm_45TTRKT5Yh28M6Qj',
"name": 'email.test'
}
]
}
Assistant
Responses are generated using AI and may contain mistakes.