> ## 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.

# Delete Organization Asset Group

> Delete an asset group. Assets in this group will become ungrouped.

## Overview

Delete an asset group from your organization. When a group is deleted, all assets assigned to that group become ungrouped. The assets themselves are not deleted - only their group assignment is removed.

## 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: "DELETE",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({
        groupId: 4,
      }),
    }
  );

  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: "DELETE",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({
        groupId: 4,
      }),
    }
  );

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

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

  response = requests.delete(
      "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,
      },
  )

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

  ```bash cURL theme={null}
  curl -X DELETE '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
    }'
  ```
</CodeGroup>

## Path Parameters

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

## Request Body

| Field   | Type   | Required | Description                                           |
| ------- | ------ | -------- | ----------------------------------------------------- |
| groupId | number | Yes      | ID of the group to delete (must match path parameter) |

## Response

### Success Response

```json theme={null}
{
  "success": true,
  "id": 4,
  "unassignedAssetCount": 5
}
```

### Response Fields

| Field                | Type    | Description                                             |
| -------------------- | ------- | ------------------------------------------------------- |
| success              | boolean | Always `true` for successful deletions                  |
| id                   | number  | ID of the deleted group                                 |
| unassignedAssetCount | number  | Number of assets that were in the group (now ungrouped) |

## Error Responses

### 400 Bad Request

Returned when the request is malformed:

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

### 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 or was already deleted:

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

## Best Practices

### Confirm Before Deletion

Always confirm before deleting a group, especially if it contains assets:

```typescript theme={null}
async function safeDeleteGroup(groupId: number) {
  // First, get 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(`About to delete group: "${group.name}"`);
  console.log(`This will unassign ${group.assetCount} asset(s)`);

  // In production, add user confirmation here
  // const confirmed = await getUserConfirmation();
  // if (!confirmed) return;

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

  const result = await deleteResponse.json();
  console.log(
    `✓ Deleted group "${group.name}", unassigned ${result.unassignedAssetCount} assets`
  );
}
```

### Reassign Assets Before Deletion

Move assets to a different group before deleting:

```typescript theme={null}
async function deleteGroupWithReassignment(
  groupId: number,
  targetGroupId: number | null
) {
  // Get all assets in the group
  const assetsResponse = await fetch(
    `https://app.chainpatrol.io/api/v2/organization/assets?groupId=${groupId}`,
    {
      headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
    }
  );

  const { assets } = await assetsResponse.json();

  console.log(`Found ${assets.length} assets to reassign`);

  // Reassign each asset
  for (const asset of assets) {
    await fetch(
      `https://app.chainpatrol.io/api/v2/organization/assets/${asset.id}`,
      {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          "X-API-KEY": "YOUR_API_KEY_HERE",
        },
        body: JSON.stringify({
          assetId: asset.id,
          groupId: targetGroupId,
        }),
      }
    );
  }

  console.log(`Reassigned ${assets.length} assets`);

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

  const result = await deleteResponse.json();
  console.log(`✓ Deleted group ${groupId}`);
  return result;
}

// Usage: Move assets to group 2 before deleting group 4
await deleteGroupWithReassignment(4, 2);

// Usage: Ungroup all assets before deleting
await deleteGroupWithReassignment(4, null);
```

### Bulk Delete with Filtering

Delete multiple groups based on criteria:

```typescript theme={null}
async function deleteEmptyGroups() {
  // Get all groups
  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();

  // Filter for empty groups
  const emptyGroups = groups.filter((g) => g.assetCount === 0);

  console.log(`Found ${emptyGroups.length} empty groups to delete`);

  const results = [];

  for (const group of emptyGroups) {
    try {
      const deleteResponse = await fetch(
        `https://app.chainpatrol.io/api/v2/organization/asset-groups/${group.id}`,
        {
          method: "DELETE",
          headers: {
            "Content-Type": "application/json",
            "X-API-KEY": "YOUR_API_KEY_HERE",
          },
          body: JSON.stringify({ groupId: group.id }),
        }
      );

      if (deleteResponse.ok) {
        const result = await deleteResponse.json();
        results.push({ id: group.id, name: group.name, success: true });
        console.log(`✓ Deleted empty group: "${group.name}"`);
      } else {
        const error = await deleteResponse.json();
        results.push({
          id: group.id,
          name: group.name,
          success: false,
          error: error.error.message,
        });
      }
    } catch (error) {
      results.push({
        id: group.id,
        name: group.name,
        success: false,
        error: String(error),
      });
    }
  }

  return results;
}

// Usage
deleteEmptyGroups().then((results) => {
  const successful = results.filter((r) => r.success).length;
  console.log(`\nDeleted ${successful} of ${results.length} empty groups`);
});
```

### Audit Trail

Log group deletions for compliance:

```typescript theme={null}
async function deleteGroupWithAudit(
  groupId: number,
  deletedBy: string,
  reason: string
) {
  // Get group details before deletion
  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) {
    throw new Error("Group not found");
  }

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

  const result = await deleteResponse.json();

  // Create audit log
  const auditLog = {
    timestamp: new Date().toISOString(),
    action: "GROUP_DELETED",
    groupId: group.id,
    groupName: group.name,
    assetCount: group.assetCount,
    unassignedAssetCount: result.unassignedAssetCount,
    deletedBy: deletedBy,
    reason: reason,
    success: result.success,
  };

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

  return result;
}

// Usage
await deleteGroupWithAudit(4, "admin@example.com", "Consolidating group structure");
```

## Use Cases

### Clean Up Unused Groups

Remove groups that haven't been used in a while:

```typescript theme={null}
async function cleanupUnusedGroups() {
  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();

  // Delete groups with 0 or very few assets
  const threshold = 3;
  const groupsToDelete = groups.filter((g) => g.assetCount <= threshold);

  console.log(`Found ${groupsToDelete.length} groups with ≤${threshold} assets`);

  for (const group of groupsToDelete) {
    console.log(`Deleting "${group.name}" (${group.assetCount} assets)...`);

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

  console.log("Cleanup complete");
}
```

### Consolidate Groups

Delete old groups and merge their assets into a new group:

```typescript theme={null}
async function consolidateGroups(
  oldGroupIds: number[],
  newGroupName: string
) {
  // Create new group
  const createResponse = await fetch(
    "https://app.chainpatrol.io/api/v2/organization/asset-groups",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "X-API-KEY": "YOUR_API_KEY_HERE",
      },
      body: JSON.stringify({ name: newGroupName }),
    }
  );

  const newGroup = await createResponse.json();
  console.log(`Created new group "${newGroup.name}" (ID: ${newGroup.id})`);

  // Move all assets from old groups to new group
  for (const oldGroupId of oldGroupIds) {
    const assetsResponse = await fetch(
      `https://app.chainpatrol.io/api/v2/organization/assets?groupId=${oldGroupId}`,
      {
        headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
      }
    );

    const { assets } = await assetsResponse.json();
    console.log(`Moving ${assets.length} assets from group ${oldGroupId}...`);

    for (const asset of assets) {
      await fetch(
        `https://app.chainpatrol.io/api/v2/organization/assets/${asset.id}`,
        {
          method: "PATCH",
          headers: {
            "Content-Type": "application/json",
            "X-API-KEY": "YOUR_API_KEY_HERE",
          },
          body: JSON.stringify({
            assetId: asset.id,
            groupId: newGroup.id,
          }),
        }
      );
    }

    // Delete old group
    await fetch(
      `https://app.chainpatrol.io/api/v2/organization/asset-groups/${oldGroupId}`,
      {
        method: "DELETE",
        headers: {
          "Content-Type": "application/json",
          "X-API-KEY": "YOUR_API_KEY_HERE",
        },
        body: JSON.stringify({ groupId: oldGroupId }),
      }
    );

    console.log(`Deleted old group ${oldGroupId}`);
  }

  console.log("Consolidation complete");
}

// Usage: Merge groups 2, 3, and 4 into "Consolidated Assets"
await consolidateGroups([2, 3, 4], "Consolidated Assets");
```

### Interactive Deletion

Provide an interactive interface for group deletion:

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

async function interactiveDeleteGroup(groupId: number) {
  // Get 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("\nGroup to be deleted:");
  console.log(`  ID: ${group.id}`);
  console.log(`  Name: ${group.name}`);
  console.log(`  Asset count: ${group.assetCount}\n`);

  if (group.assetCount > 0) {
    console.log(
      `⚠️  Warning: This group contains ${group.assetCount} asset(s) that will become ungrouped.\n`
    );
  }

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

  rl.question(
    'Type the group name to confirm deletion (or press Enter to cancel): ',
    async (confirmation) => {
      if (confirmation !== group.name) {
        console.log("Deletion cancelled");
        rl.close();
        return;
      }

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

      if (deleteResponse.ok) {
        const result = await deleteResponse.json();
        console.log(
          `\n✓ Group deleted successfully. Unassigned ${result.unassignedAssetCount} assets.`
        );
      } else {
        const error = await deleteResponse.json();
        console.error(`\n✗ Failed to delete: ${error.error.message}`);
      }

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

## Common Error Messages

| Error Message                              | Cause                                     | Resolution                            |
| ------------------------------------------ | ----------------------------------------- | ------------------------------------- |
| Group with ID {id} not found               | Invalid group ID or already deleted       | 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 |
| Group ID is required                       | Missing `groupId` field in request        | Provide a `groupId` field             |
| Path parameter groupId does not match body | Mismatch between URL and body group IDs   | Ensure both group IDs match           |

## Notes

* Deleting a group does **not** delete the assets - they become ungrouped
* The `unassignedAssetCount` in the response shows how many assets were affected
* Organization is automatically determined from your API key
* The group ID must match in both the URL path and request body
* Empty groups (with 0 assets) can be safely deleted without side effects
* This operation cannot be undone - consider exporting group data before deletion
* Ungrouped assets can be reassigned to groups at any time using the update asset endpoint


## OpenAPI

````yaml DELETE /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}:
    delete:
      tags:
        - organization
      summary: Delete asset group
      description: Delete an asset group. Assets in this group will become ungrouped.
      operationId: organizationAssetGroupsDelete
      parameters:
        - in: path
          name: groupId
          description: ID of the group to delete
          schema:
            type: integer
            minimum: 0
            exclusiveMinimum: true
          required: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  id:
                    type: number
                  unassignedAssetCount:
                    type: number
                required:
                  - success
                  - id
                  - unassignedAssetCount
        '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.

````