---
title: "Bulk Create Or Replace Roles"
method: PUT
path: "/v2/schema/{proj_id}/{env_id}/bulk/roles"
tags: ["Bulk Operations"]
---

# Bulk Create Or Replace Roles

`PUT /v2/schema/{proj_id}/{env_id}/bulk/roles`

Create or replace roles in bulk.

## Path parameters

- `proj_id` string, required — Either the unique id of the project, or the URL-friendly key of the project (i.e: the "slug").
- `env_id` string, required — Either the unique id of the environment, or the URL-friendly key of the environment (i.e: the "slug").

## Request body

- RoleCreateBulkOperation
  - `operations` RoleCreateBulk[], required
    - `name` string, required — The name of the role
    - `description` string — optional description string explaining what this role represents, or what permissions are granted to it.
    - `permissions` string[] — list of action keys that define what actions this resource role is permitted to do
    - `attributes` object — optional dictionary of key-value pairs that can be used to store arbitrary metadata about this role. This metadata can be used to filter role using query parameters with attr_ prefix, currently supports only 'equals' operator
    - `extends` string[] — list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
    - `granted_to` DerivedRoleBlockEdit
      - `when` PermitBackendSchemasSchemaDerivedRoleRuleDerivationSettings — Settings for a derived role or a derived role rule
        - `no_direct_roles_on_object` boolean — If true, the derived role or the specific rule will not apply if the resource has any direct role
      - `users_with_role` DerivedRoleRuleCreate[] — the rules of the derived role
        - `role` string, required — the role key that needs to exist on the related resource (from the relation)
        - `on_resource` string, required — the resource key that needs to exist on the related role (from the relation)
        - `linked_by_relation` string, required — the relation key that needs to exist between the resource and the related resource
        - `when` PermitBackendSchemasSchemaDerivedRoleRuleDerivationSettings — Settings for a derived role or a derived role rule
          - `no_direct_roles_on_object` boolean — If true, the derived role or the specific rule will not apply if the resource has any direct role
    - `v1compat_settings` object
    - `v1compat_attributes` object
    - `key` string, required — A URL-friendly name of the Role (i.e: slug). You will be able to query later using this key instead of the id (UUID) of the Role.
    - `resource` string — The resource key for the role. Optional; for tenant roles, leave empty.

## Response `200`

Successful Response

- RoleCreateBulkOperationResult
  - `created` string[], required
  - `updated` string[], required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/permit/apis/permit-io-api.md) · [All operations](https://skmtc.dev/permit/apis/permit-io-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/permit/permit-io-api/revisions/13faa12b4692/schema)
