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

# Update Organization Asset Group

> Rename an existing asset group.

## Overview

Rename an existing asset group. This endpoint allows you to update the display name of a group belonging to your organization. All assets assigned to this group will remain assigned after the rename.

## Quick Start

### Authentication

Include your API key in the `X-API-KEY` header:

```bash theme={null}
X-API-KEY: your_api_key_here
```

### Example Request

<CodeGroup>
  ```typescript TypeScript theme={null}
  const response = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups/4",
    {
      method: "PATCH",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({
        groupId: 4,
        name: "Renamed Group",
      }),
    }
  );

  const data = await response.json();
  console.log(data);
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups/4",
    {
      method: "PATCH",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({
        groupId: 4,
        name: "Renamed Group",
      }),
    }
  );

  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.patch(
      "https://app.chainpatrol.io/api/v2/organization/asset-groups/4",
      headers={
          "Content-Type": "application/json",
          "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      json={
          "groupId": 4,
          "name": "Renamed Group",
      },
  )

  data = response.json()
  print(data)
  ```

  ```bash cURL theme={null}
  curl -X PATCH 'https://app.chainpatrol.io/api/v2/organization/asset-groups/4' \
    -H 'X-API-KEY: YOUR_API_KEY_HERE' \
    -H 'Content-Type: application/json' \
    -d '{
      "groupId": 4,
      "name": "Renamed Group"
    }'
  ```
</CodeGroup>

## Path Parameters

| Parameter | Type   | Required | Description               |
| --------- | ------ | -------- | ------------------------- |
| groupId   | number | Yes      | ID of the group to update |

## Request Body

| Field   | Type   | Required | Description                                           |
| ------- | ------ | -------- | ----------------------------------------------------- |
| groupId | number | Yes      | ID of the group to update (must match path parameter) |
| name    | string | Yes      | New name for the group (1-255 characters)             |

## Response

### Success Response

```json theme={null}
{
  "id": 4,
  "name": "Renamed Group"
}
```

### Response Fields

| Field | Type   | Description        |
| ----- | ------ | ------------------ |
| id    | number | Group ID           |
| name  | string | Updated group name |

## Error Responses

### 400 Bad Request

Returned when the request is malformed or validation fails:

```json theme={null}
{
  "error": {
    "code": "BAD_REQUEST",
    "message": "Group name is required"
  }
}
```

```json theme={null}
{
  "error": {
    "code": "BAD_REQUEST",
    "message": "Group name must be between 1 and 255 characters"
  }
}
```

### 401 Unauthorized

Returned when the API key is missing, invalid, or doesn't have organization access:

```json theme={null}
{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "API key with organization access required"
  }
}
```

### 403 Forbidden

Returned when the group doesn't belong to your organization:

```json theme={null}
{
  "error": {
    "code": "FORBIDDEN",
    "message": "Group does not belong to your organization"
  }
}
```

### 404 Not Found

Returned when the group doesn't exist:

```json theme={null}
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Group with ID 4 not found"
  }
}
```

### 409 Conflict

Returned when a group with the new name already exists:

```json theme={null}
{
  "error": {
    "code": "CONFLICT",
    "message": "A group with this name already exists"
  }
}
```

## Best Practices

### Validation Before Rename

Check if a group with the target name already exists:

```typescript theme={null}
async function safeRenameGroup(groupId: number, newName: string) {
  // Check if name is already in use
  const listResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { groups } = await listResponse.json();
  const existingGroup = groups.find(
    (g) => g.name.toLowerCase() === newName.toLowerCase() && g.id !== groupId
  );

  if (existingGroup) {
    console.error(`Group name "${newName}" is already in use by group ${existingGroup.id}`);
    return null;
  }

  // Proceed with rename
  const updateResponse = await fetch(
    `https://app.chainpatrol.io/api/v2/organization/asset-groups/${groupId}`,
    {
      method: "PATCH",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({ groupId, name: newName }),
    }
  );

  const updatedGroup = await updateResponse.json();
  console.log(`Successfully renamed group to "${updatedGroup.name}"`);
  return updatedGroup;
}
```

### Bulk Rename with Prefix/Suffix

Add a prefix or suffix to multiple groups:

```typescript theme={null}
async function addPrefixToGroups(prefix: string, groupIds: number[]) {
  // First, get current group names
  const listResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { groups } = await listResponse.json();
  const results = [];

  for (const groupId of groupIds) {
    const group = groups.find((g) => g.id === groupId);
    if (!group) {
      results.push({ id: groupId, success: false, error: "Group not found" });
      continue;
    }

    const newName = `${prefix}${group.name}`;

    try {
      const updateResponse = await fetch(
        `https://app.chainpatrol.io/api/v2/organization/asset-groups/${groupId}`,
        {
          method: "PATCH",
          headers: {
            "Content-Type": "application/json",
            "X-API-KEY": "YOUR_API_KEY_HERE",
          },
          body: JSON.stringify({ groupId, name: newName }),
        }
      );

      if (updateResponse.ok) {
        const updated = await updateResponse.json();
        results.push({ id: groupId, success: true, newName: updated.name });
      } else {
        const error = await updateResponse.json();
        results.push({ id: groupId, success: false, error: error.error.message });
      }
    } catch (error) {
      results.push({ id: groupId, success: false, error: String(error) });
    }
  }

  return results;
}

// Usage
addPrefixToGroups("Archive - ", [1, 2, 3]).then((results) => {
  results.forEach((r) => {
    if (r.success) {
      console.log(`✓ Renamed group ${r.id} to "${r.newName}"`);
    } else {
      console.log(`✗ Failed to rename group ${r.id}: ${r.error}`);
    }
  });
});
```

### Audit Trail

Log group renames for audit purposes:

```typescript theme={null}
async function renameGroupWithAudit(
  groupId: number,
  newName: string,
  renamedBy: string,
  reason: string
) {
  // Get current group details
  const listResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { groups } = await listResponse.json();
  const currentGroup = groups.find((g) => g.id === groupId);

  if (!currentGroup) {
    throw new Error(`Group ${groupId} not found`);
  }

  const oldName = currentGroup.name;

  // Perform rename
  const updateResponse = await fetch(
    `https://app.chainpatrol.io/api/v2/organization/asset-groups/${groupId}`,
    {
      method: "PATCH",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({ groupId, name: newName }),
    }
  );

  const updatedGroup = await updateResponse.json();

  // Create audit log
  const auditLog = {
    timestamp: new Date().toISOString(),
    action: "GROUP_RENAMED",
    groupId: groupId,
    oldName: oldName,
    newName: newName,
    renamedBy: renamedBy,
    reason: reason,
    assetCount: currentGroup.assetCount,
  };

  console.log("Audit log:", JSON.stringify(auditLog));
  // await sendToAuditSystem(auditLog);

  return updatedGroup;
}

// Usage
await renameGroupWithAudit(
  4,
  "Legacy Wallets",
  "admin@example.com",
  "Reorganizing wallet groups by status"
);
```

## Use Cases

### Standardize Naming Convention

Rename groups to follow a consistent naming convention:

```typescript theme={null}
async function standardizeGroupNames() {
  const listResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { groups } = await listResponse.json();

  // Define naming standards
  const nameMapping = {
    urls: "Official Websites",
    wallets: "Blockchain Addresses",
    social: "Social Media Accounts",
    contracts: "Smart Contracts",
  };

  for (const group of groups) {
    const lowerName = group.name.toLowerCase();
    const standardName = nameMapping[lowerName];

    if (standardName && standardName !== group.name) {
      await fetch(
        `https://app.chainpatrol.io/api/v2/organization/asset-groups/${group.id}`,
        {
          method: "PATCH",
          headers: {
            "Content-Type": "application/json",
            "X-API-KEY": "YOUR_API_KEY_HERE",
          },
          body: JSON.stringify({ groupId: group.id, name: standardName }),
        }
      );
      console.log(`Renamed "${group.name}" to "${standardName}"`);
    }
  }
}
```

### Migrate Group Structure

Rename groups as part of a structural migration:

```typescript theme={null}
async function migrateGroupStructure() {
  const migrations = [
    { oldName: "Production URLs", newName: "Prod - Websites" },
    { oldName: "Production Wallets", newName: "Prod - Addresses" },
    { oldName: "Staging URLs", newName: "Staging - Websites" },
    { oldName: "Staging Wallets", newName: "Staging - Addresses" },
  ];

  const listResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { groups } = await listResponse.json();

  for (const migration of migrations) {
    const group = groups.find((g) => g.name === migration.oldName);
    
    if (group) {
      await fetch(
        `https://app.chainpatrol.io/api/v2/organization/asset-groups/${group.id}`,
        {
          method: "PATCH",
          headers: {
            "Content-Type": "application/json",
            "X-API-KEY": "YOUR_API_KEY_HERE",
          },
          body: JSON.stringify({ groupId: group.id, name: migration.newName }),
        }
      );
      console.log(`Migrated: "${migration.oldName}" → "${migration.newName}"`);
    }
  }
}
```

### Interactive Rename

Provide an interactive interface for renaming:

```typescript theme={null}
import * as readline from "readline";

async function interactiveRename(groupId: number) {
  // Get current group details
  const listResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { groups } = await listResponse.json();
  const group = groups.find((g) => g.id === groupId);

  if (!group) {
    console.error("Group not found");
    return;
  }

  console.log(`\nCurrent group name: "${group.name}"`);
  console.log(`Asset count: ${group.assetCount}\n`);

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });

  rl.question("Enter new name (or press Enter to cancel): ", async (newName) => {
    if (!newName.trim()) {
      console.log("Rename cancelled");
      rl.close();
      return;
    }

    const updateResponse = await fetch(
      `https://app.chainpatrol.io/api/v2/organization/asset-groups/${groupId}`,
      {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          "X-API-KEY": "YOUR_API_KEY_HERE",
        },
        body: JSON.stringify({ groupId, name: newName }),
      }
    );

    if (updateResponse.ok) {
      const updated = await updateResponse.json();
      console.log(`\n✓ Group renamed to "${updated.name}"`);
    } else {
      const error = await updateResponse.json();
      console.error(`\n✗ Failed to rename: ${error.error.message}`);
    }

    rl.close();
  });
}
```

## Common Error Messages

| Error Message                                   | Cause                                     | Resolution                            |
| ----------------------------------------------- | ----------------------------------------- | ------------------------------------- |
| Group with ID {id} not found                    | Invalid group ID                          | Verify the group ID exists            |
| Group does not belong to your organization      | Group belongs to a different organization | Use a group ID from your organization |
| A group with this name already exists           | Duplicate group name                      | Choose a different name               |
| Group name is required                          | Missing `name` field in request           | Provide a `name` field                |
| Group name must be between 1 and 255 characters | Name is too short or too long             | Use a name with 1-255 characters      |
| Path parameter groupId does not match body      | Mismatch between URL and body group IDs   | Ensure both group IDs match           |

## Notes

* Group names must be unique within your organization
* Names are case-sensitive for uniqueness checks
* All assets assigned to the group remain assigned after rename
* Organization is automatically determined from your API key
* The group ID must match in both the URL path and request body
* Renaming a group does not affect asset assignments or asset metadata
* Group's asset count is not affected by rename operations


## OpenAPI

````yaml PATCH /organization/asset-groups/{groupId}
openapi: 3.0.3
info:
  title: ChainPatrol External API - OpenAPI 3.0
  description: ChainPatrol External API documentation
  version: 2.0.0
servers:
  - url: https://app.chainpatrol.io/api/v2
security: []
tags:
  - name: asset
  - name: report
externalDocs:
  url: https://chainpatrol.com/docs
paths:
  /organization/asset-groups/{groupId}:
    patch:
      tags:
        - organization
      summary: Update asset group
      description: Rename an existing asset group.
      operationId: organizationAssetGroupsUpdate
      parameters:
        - in: path
          name: groupId
          description: ID of the group to update
          schema:
            type: integer
            minimum: 0
            exclusiveMinimum: true
          required: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
              required:
                - name
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: number
                  name:
                    type: string
                required:
                  - id
                  - name
        '400':
          description: Invalid input data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BAD_REQUEST'
        '401':
          description: Authorization not provided
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.UNAUTHORIZED'
        '403':
          description: Insufficient access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.FORBIDDEN'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.NOT_FOUND'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.INTERNAL_SERVER_ERROR'
      security:
        - ApiKey: []
components:
  schemas:
    error.BAD_REQUEST:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Invalid input data
        code:
          type: string
          description: The error code
          example: BAD_REQUEST
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Invalid input data error (400)
      description: The error information
      example:
        code: BAD_REQUEST
        message: Invalid input data
        issues: []
    error.UNAUTHORIZED:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Authorization not provided
        code:
          type: string
          description: The error code
          example: UNAUTHORIZED
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Authorization not provided error (401)
      description: The error information
      example:
        code: UNAUTHORIZED
        message: Authorization not provided
        issues: []
    error.FORBIDDEN:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Insufficient access
        code:
          type: string
          description: The error code
          example: FORBIDDEN
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Insufficient access error (403)
      description: The error information
      example:
        code: FORBIDDEN
        message: Insufficient access
        issues: []
    error.NOT_FOUND:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Not found
        code:
          type: string
          description: The error code
          example: NOT_FOUND
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Not found error (404)
      description: The error information
      example:
        code: NOT_FOUND
        message: Not found
        issues: []
    error.INTERNAL_SERVER_ERROR:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Internal server error
        code:
          type: string
          description: The error code
          example: INTERNAL_SERVER_ERROR
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Internal server error error (500)
      description: The error information
      example:
        code: INTERNAL_SERVER_ERROR
        message: Internal server error
        issues: []
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: X-API-KEY
      description: >-
        Your API key. This is required by most endpoints to access our API
        programatically. Reach out to us at
        [support@chainpatrol.io](mailto:support@chainpatrol.io?subject=Re:%20API%20Key%20for%20SDK&body=Company:%20%0AName:%20%0APurpose:%20)
        to get an API key for your use.

````