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

# Update Role

> Update an existing role

## Path Parameters

<ParamField path="organizationId" type="string" required>
  Organization ID
</ParamField>

<ParamField path="roleId" type="string" required>
  Role ID
</ParamField>

## Request Body

<ParamField body="name" type="string">
  Updated role name
</ParamField>

<ParamField body="description" type="string">
  Updated description
</ParamField>

<ParamField body="permissions" type="object">
  Updated permission settings (partial updates supported)
</ParamField>

### Example Request

```json theme={null}
{
  "description": "Updated role description",
  "permissions": {
    "content": {
      "publish": true
    }
  }
}
```

## Response

Returns the updated Role object.

```json theme={null}
{
  "id": "role123",
  "name": "editor",
  "description": "Updated role description",
  "permissions": {
    "organizations": { "read": true, "update": false, "delete": false },
    "content": { "create": true, "read": true, "update": true, "publish": true, "delete": true }
  },
  "createdAt": "2024-03-20T10:00:00Z",
  "updatedAt": "2024-03-22T14:00:00Z"
}
```

## Error Responses

### Role Not Found

```json theme={null}
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Role not found"
  }
}
```

### Role Name Already Exists

```json theme={null}
{
  "error": {
    "code": "ROLE_NAME_ALREADY_EXISTS",
    "message": "Role with name \"editor\" already exists"
  }
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT "https://api.metabind.ai/app/v1/organizations/org123/roles/role123" \
    -H "Authorization: Bearer YOUR_JWT" \
    -H "Content-Type: application/json" \
    -d '{
      "description": "Updated role description",
      "permissions": {
        "content": { "publish": true }
      }
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://api.metabind.ai/app/v1/organizations/org123/roles/role123',
    {
      method: 'PUT',
      headers: {
        'Authorization': 'Bearer YOUR_JWT',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        description: 'Updated role description',
        permissions: {
          content: { publish: true }
        }
      })
    }
  );

  const role = await response.json();
  console.log(`Updated role: ${role.name}`);
  ```

  ```swift Swift theme={null}
  var request = URLRequest(url: URL(string: "https://api.metabind.ai/app/v1/organizations/org123/roles/role123")!)
  request.httpMethod = "PUT"
  request.setValue("Bearer YOUR_JWT", forHTTPHeaderField: "Authorization")
  request.setValue("application/json", forHTTPHeaderField: "Content-Type")

  let body = ["description": "Updated role description"]
  request.httpBody = try JSONEncoder().encode(body)

  let (data, _) = try await URLSession.shared.data(for: request)
  ```

  ```kotlin Kotlin theme={null}
  val response = client.put("https://api.metabind.ai/app/v1/organizations/org123/roles/role123") {
      header("Authorization", "Bearer YOUR_JWT")
      contentType(ContentType.Application.Json)
      setBody(mapOf("description" to "Updated role description"))
  }
  ```
</CodeGroup>
