> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bedrock.quarry-systems.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Scopes (Batch)

> Create multiple scopes with inline memberships in a single request

## Overview

Batch creation allows you to create multiple scopes in a single API call. You can provide client IDs for in-batch references, set up parent relationships, and add memberships with role assignments.

<Info>
  **ID Format**: All IDs use a namespaced UUIDv7 format: `scope_{uuidv7}`. You can optionally provide your own IDs for in-batch references.
</Info>

## Request Body

Array of scope objects:

<ParamField body="[].id" type="string">
  Optional client-provided ID. Useful for referencing within the same batch.
</ParamField>

<ParamField body="[].typeId" type="string" required>
  ID of the scope type
</ParamField>

<ParamField body="[].name" type="string">
  Display name for the scope
</ParamField>

<ParamField body="[].externalId" type="string">
  External identifier for the scope
</ParamField>

<ParamField body="[].meta" type="object">
  Optional metadata to associate with the scope
</ParamField>

<ParamField body="[].parentScopeId" type="string">
  Optional parent scope ID. Automatically creates a scope hierarchy edge.
</ParamField>

<ParamField body="[].memberships" type="array">
  Optional array of inline memberships. Each membership has:

  * `subjectId` (required): The subject to add to this scope
  * `roleIds` (optional): Array of role IDs to assign
</ParamField>

## Response

Returns an array of created scope objects.

<Note>
  Each scope can include `parentScopeId` and `memberships` to set up the complete structure in one request.
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://api.example.com/scopes/batch' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '[
      {
        "id": "scope_engineering",
        "typeId": "type_department",
        "name": "Engineering",
        "parentScopeId": "scope_env_production",
        "memberships": [
          {"subjectId": "subject_jane", "roleIds": ["role_admin"]}
        ]
      },
      {
        "id": "scope_backend",
        "typeId": "type_team",
        "name": "Backend Team",
        "parentScopeId": "scope_engineering",
        "memberships": [
          {"subjectId": "subject_jane", "roleIds": ["role_lead"]},
          {"subjectId": "subject_bob", "roleIds": ["role_developer"]},
          {"subjectId": "subject_alice", "roleIds": ["role_developer"]}
        ]
      },
      {
        "id": "scope_frontend",
        "typeId": "type_team",
        "name": "Frontend Team",
        "parentScopeId": "scope_engineering",
        "memberships": [
          {"subjectId": "subject_charlie", "roleIds": ["role_lead"]}
        ]
      }
    ]'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  [
    {
      "id": "scope_engineering",
      "typeId": "type_department",
      "name": "Engineering"
    },
    {
      "id": "scope_backend",
      "typeId": "type_team",
      "name": "Backend Team"
    },
    {
      "id": "scope_frontend",
      "typeId": "type_team",
      "name": "Frontend Team"
    }
  ]
  ```
</ResponseExample>

## Examples

### Basic Batch

```bash theme={null}
curl -X POST 'https://api.example.com/scopes/batch' \
  -d '[
    {"typeId": "type_team", "name": "Team A"},
    {"typeId": "type_team", "name": "Team B"},
    {"typeId": "type_team", "name": "Team C"}
  ]'
```

### With In-Batch Parent References

Use client-provided IDs to reference scopes within the same batch:

```bash theme={null}
curl -X POST 'https://api.example.com/scopes/batch' \
  -d '[
    {
      "id": "scope_dept",
      "typeId": "type_department",
      "name": "Engineering"
    },
    {
      "typeId": "type_team",
      "name": "Backend",
      "parentScopeId": "scope_dept"
    },
    {
      "typeId": "type_team",
      "name": "Frontend",
      "parentScopeId": "scope_dept"
    }
  ]'
```
