# Update Account Group

Updates the details of an existing account group: its name, its merchant ID, or the group it is nested under.

Only the fields present in the body are changed. `parent_code` has three states: omit it to leave the parent untouched, send `null` to detach the group and make it a root again, or send another group's `id` to nest the group under it. Nesting is structural only — it does not grant or revoke any permission.

**PATCH** `/organizations/account-groups/{account_group_id}`

Base URL: `https://api-sandbox.whitelabel.com/v1`

Updates an account group. Every field is optional and only the fields present in the body are changed.

`parent_code` nests the group under another group of the same organization. It has three states: **absent** leaves the current parent untouched; **`null`** detaches the group and promotes it back to a root, together with any sub-groups hanging off it; a **group `id`** nests the group under that group. Nesting is structural only — it grants and revokes nothing, so moving a group leaves every existing permission untouched.

## Authorization

- PUBLIC-API-KEY (apiKey in header)
- PRIVATE-SECRET-KEY (apiKey in header)

## Path parameters

- `account_group_id` (string, required)
  Account group UUID.

## Body

Content type: `application/json`

- `name` (string)
  Account group name (min=1, max=255).
- `merchant_id` (string)
  Local identifier (min=1, max=255).
- `parent_code` (string,null<uuid>)
  The `id` of the group to nest this group under. Omit it to leave the parent unchanged; send `null` to detach the group and make it a root again. The parent must belong to the same organization and must not be the group itself or one of its descendants.

Example:

```json
{
  "name": "string",
  "merchant_id": "string",
  "parent_code": null
}
```

## Responses

### 200

OK

- `id` (string<uuid>)
- `name` (string)
- `merchant_id` (string)
- `parent_code` (string,null<uuid>)
  The `id` of the group this group is nested under. `null` for a root (top-level) group.
- `created_at` (string<date-time>)
- `updated_at` (string<date-time>)

Example:

```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "string",
  "merchant_id": "string",
  "parent_code": null,
  "created_at": "1970-01-01T00:00:00.000Z",
  "updated_at": "1970-01-01T00:00:00.000Z"
}
```

### 400

Bad Request. The `code` field tells the reason:

- `PARENT_NOT_FOUND` — no group with that `parent_code` in this organization.
- `INVALID_PARENT` — the group was sent as its own parent.
- `PARENT_IS_DESCENDANT` — the target parent sits inside this group's own subtree, so the move would create a cycle.
- `MAX_NESTING_DEPTH` — the move would push the tree past the maximum depth of 20 levels.

- `code` (string)
  Machine-readable error code.
- `messages` (string[])
  Human-readable details.

Example:

```json
{
  "code": "string",
  "messages": [
    "string"
  ]
}
```

### 404

Not Found — no account group with that `account_group_id` in this organization.