# Roles

Source: https://www.pontive.com/docs/api-reference/management/roles

Base URL: `https://api.{region}.pontive.com/v1` (operations that name another server say so).

Authentication: send `Authorization: Bearer <token>` with a secret key (`pontive_sk_…`, which implies its instance) or an access token issued for this API. A token that can reach several instances also names one with `X-Pontive-Instance-ID: inst_…`. Secret keys are for servers only.

## List a resource type's roles

```http
GET https://api.{region}.pontive.com/v1/authz/resource-types/{resource_type}/roles
```

The roles of one resource type (D18), filtered as GET /authz/roles is. With inheritable_from, the roles of that parent type a role on this type could inherit instead: each a valid parent_role_key for a RoleInheritance rule on it.

Operation ID: `ListResourceTypeRoles`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resource_type` | string | yes | Resource type key |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `inheritable_from` | string |  | A parent type: list its roles this type's roles may inherit |
| `type` | string |  | Filter by role type (system, custom) |
| `name` | string |  | Filter by role name (partial match) |
| `resource_id` | string |  | Also include this organization instance's own instance-scoped roles |
| `include_instance_scoped` | boolean |  | Include every instance-scoped role alongside type-scoped ones (ignored when resource_id is set) |
| `assignable_only` | boolean |  | Only roles that may be assigned directly |
| `agent_assignable_only` | boolean |  | Only roles an agent may hold |
| `permission` | string |  | Filter by permission name |
| `page` | integer |  | Page number |
| `limit` | integer |  | Items per page |

### Responses

- `200` OK: ListRolesResponse
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Create custom role

```http
POST https://api.{region}.pontive.com/v1/authz/resource-types/{resource_type}/roles
```

Create a custom role. Required: key, resource_type, permissions. Optional: description, name, metadata, resource_id. Setting resource_id (an organization id) makes the role instance-scoped — assignable only on that instance; it is immutable. Role keys are unique within a resource type and cannot collide with system roles.

Operation ID: `CreateRole`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resource_type` | string | yes | resource_type |

### Request body (`application/json`, required): CreateRoleRequest

Create Role Request

### Responses

- `201` Created: Role
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Get role details

```http
GET https://api.{region}.pontive.com/v1/authz/resource-types/{resource_type}/roles/{role_key}
```

Get a role by key and resource_type. Returns name, description, resource_type, type, permissions, metadata, created_at, updated_at, assignment_count, permission_count.

Operation ID: `GetRole`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resource_type` | string | yes | Role resource type |
| `role_key` | string | yes | Role Key |

### Responses

- `200` OK: Role
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `404` Not Found: ErrResponse
- `500` Internal Server Error: ErrResponse

## Update custom role

```http
PATCH https://api.{region}.pontive.com/v1/authz/resource-types/{resource_type}/roles/{role_key}
```

Update a custom role. Can update: description, name, permissions, metadata. Cannot update: key (immutable), resource_type (immutable). System roles cannot be updated.

Operation ID: `UpdateRole`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resource_type` | string | yes | Role resource type |
| `role_key` | string | yes | Role Key |

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `If-Match` | string |  | The ETag the document was read with: a stale one is refused 412 precondition_failed (D42) |

### Request body (`application/json`): UpdateRoleRequest

Update Role Request

### Responses

- `200` OK: Role
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `404` Not Found: ErrResponse
- `412` precondition_failed: the document changed since it was read: ErrResponse
- `500` Internal Server Error: ErrResponse

## Delete custom role

```http
DELETE https://api.{region}.pontive.com/v1/authz/resource-types/{resource_type}/roles/{role_key}
```

Delete a custom role. System roles cannot be deleted. Returns 204 No Content on success.

Operation ID: `DeleteRole`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `resource_type` | string | yes | Role resource type |
| `role_key` | string | yes | Role Key |

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `force` | boolean |  | Force delete (bypass confirmation when role is in use) |

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `If-Match` | string |  | The ETag the document was read with: a stale one is refused 412 precondition_failed (D42) |

### Responses

- `204` No Content
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `404` Not Found: ErrResponse
- `412` precondition_failed: the document changed since it was read: ErrResponse
- `500` Internal Server Error: ErrResponse

## List roles

```http
GET https://api.{region}.pontive.com/v1/authz/roles
```

Get a paginated list of roles (system and custom) in the directory. Filter by type (system/custom), resource_type, name (partial match), permission. By default only type-scoped roles are returned. Pass resource_id to also include that organization instance's own instance-scoped roles, or set include_instance_scoped=true to include every instance-scoped role alongside the type-scoped ones (ignored when resource_id is set).

Operation ID: `ListRoles`

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | string |  | Filter by role type (system, custom) |
| `name` | string |  | Filter by role name (partial match) |
| `resource_type` | string |  | Filter by resource type |
| `resource_id` | string |  | Also include this organization instance's own instance-scoped roles |
| `include_instance_scoped` | boolean |  | Include every instance-scoped role alongside type-scoped ones (ignored when resource_id is set) |
| `assignable_only` | boolean |  | Only roles that may be assigned directly: drops inherited-only roles. What a role picker asks for |
| `agent_assignable_only` | boolean |  | Only roles an agent may hold (agent_assignable): what an agent's role picker asks for |
| `permission` | string |  | Filter by permission name |
| `page` | integer |  | Page number |
| `limit` | integer |  | Items per page |
| `sort` | string |  | Sort field; prefix with - for descending (e.g. -created_at). Allowed: created_at, updated_at, name, key. Default: -created_at |
| `search` | string |  | Search query |

### Responses

- `200` OK: ListRolesResponse
- `400` Bad Request: ErrResponse
- `401` Unauthorized: ErrResponse
- `403` Forbidden: ErrResponse
- `500` Internal Server Error: ErrResponse

## Schemas

### ListRolesResponse

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | Role[] |  |  |
| `object` | string |  |  |
| `pagination` | Pagination |  | Pagination is the page answered (api-route-review D9). |

### ErrResponse

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | ErrBody |  |  |

### CreateRoleRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `agent_assignable` | boolean |  | AgentAssignable sets whether an agent may hold the role; omitted is true (pontive-spec 45 §6.2). |
| `description` | string |  |  |
| `inheritance` | RoleInheritance[] |  | Inheritance is the optional set of inheritance rules, at most one per parent type. Each parent_type must be a declared parent type of resource_type, and each parent role key must exist on it. |
| `inherited_only` | boolean |  | InheritedOnly makes the role held only through a parent role, never assigned directly. Requires inheritance; not on the root type. |
| `key` | string | yes |  |
| `metadata` | Record<string, string> |  |  |
| `name` | string |  |  |
| `permissions` | string[] |  |  |
| `resource_id` | string |  | ResourceID, when set, creates an instance-scoped role bound to this organization. Optional and immutable; omit for a type-scoped role (the default). |

### Role

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `agent_assignable` | boolean |  | AgentAssignable: an agent may hold the role through an installation (pontive-spec 45 §6.2). The seeded org and root owner roles are false; every other role defaults to true. |
| `assignment_count` | integer |  |  |
| `created_at` | string |  |  |
| `description` | string |  |  |
| `inheritance` | RoleInheritance[] |  |  |
| `inherited_only` | boolean |  | InheritedOnly: the role is held only through a parent role and can never be assigned directly to a member, group, service account or invitation (role_not_assignable). Pickers drop it (assignable_only). |
| `key` | string |  |  |
| `metadata` | Record<string, string> |  |  |
| `name` | string |  |  |
| `object` | string |  |  |
| `permission_count` | integer |  |  |
| `permissions` | string[] |  |  |
| `resource_id` | string |  |  |
| `resource_type` | string |  |  |
| `type` | "system" \| "custom" |  |  |
| `updated_at` | string |  |  |

### UpdateRoleRequest

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `agent_assignable` | boolean |  | AgentAssignable, when provided, sets whether an agent may hold the role. Turning it off is refused while an agent installation holds the role or an agent requests it (409 role_held_by_agents). |
| `description` | string |  |  |
| `inheritance` | RoleInheritance[] |  | Inheritance follows the same absent-vs-empty convention as permissions: omitted leaves existing rules unchanged; a provided (possibly empty) list replaces them wholesale. |
| `inherited_only` | boolean |  | InheritedOnly, when provided, turns the flag on or off. Turning it on is refused while anything holds the role directly (role_in_use), on the root type, without inheritance, or on a seeded role. |
| `metadata` | Record<string, string> |  |  |
| `name` | string |  |  |
| `permissions` | string[] |  |  |

### Pagination

Pagination is the page answered (api-route-review D9).

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `limit` | integer |  | Limit is the maximum number of items per page. |
| `page` | integer |  | Page is the 1-based index of the returned page. |
| `total` | integer |  | Total is the total number of items across all pages. |
| `total_pages` | integer |  | TotalPages is the total number of pages available. |

### ErrBody

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string |  | Code is the spec's machine-readable code for this error, in snake case: a domain code such as seat_limit_reached where the refusal has one, otherwise a generic one such as permission_denied, not_found, conflict, invalid_request or service_unavailable. |
| `details` | ErrDetail[] |  | Details are per-field findings, present only on a refusal that has them, e.g. a 422 invalid_theme names each invalid value by its path, a 422 package_invalid each problem, and a 409 capability_in_use each count by its name. |
| `doc_url` | string |  | DocURL links to documentation about this error, when available. |
| `message` | string |  | Message is a human-readable description of what went wrong. |
| `object` | string |  | Object is the discriminator; always "error". |
| `param` | string |  | Param names the request parameter this error refers to, when applicable. |
| `type` | "validation_error" \| "authentication_error" \| "authorization_error" \| "not_found" \| "conflict_error" \| "rate_limit_error" \| "internal_error" |  | Type is the error's category, set by its HTTP status: one of validation_error, authentication_error, authorization_error, not_found, conflict_error, rate_limit_error, internal_error. |

### RoleInheritance

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `parent_role_keys` | string[] |  |  |
| `parent_type` | string |  |  |

### ErrDetail

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `field` | string |  | Field is where the finding is: for a theme, its dotted path. |
| `message` | string |  | Message is what is wrong there. |
