Skip to main content
PATCH
/
organization
/
asset-groups
/
{groupId}
Update asset group
curl --request PATCH \
  --url https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId} \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <api-key>' \
  --data '
{
  "name": "<string>"
}
'
{
  "id": 123,
  "name": "<string>"
}

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:
X-API-KEY: your_api_key_here

Example Request

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);

Path Parameters

ParameterTypeRequiredDescription
groupIdnumberYesID of the group to update

Request Body

FieldTypeRequiredDescription
groupIdnumberYesID of the group to update (must match path parameter)
namestringYesNew name for the group (1-255 characters)

Response

Success Response

{
  "id": 4,
  "name": "Renamed Group"
}

Response Fields

FieldTypeDescription
idnumberGroup ID
namestringUpdated group name

Error Responses

400 Bad Request

Returned when the request is malformed or validation fails:
{
  "error": {
    "code": "BAD_REQUEST",
    "message": "Group name is required"
  }
}
{
  "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:
{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "API key with organization access required"
  }
}

403 Forbidden

Returned when the group doesn’t belong to your organization:
{
  "error": {
    "code": "FORBIDDEN",
    "message": "Group does not belong to your organization"
  }
}

404 Not Found

Returned when the group doesn’t exist:
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Group with ID 4 not found"
  }
}

409 Conflict

Returned when a group with the new name already exists:
{
  "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:
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:
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:
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",
  "[email protected]",
  "Reorganizing wallet groups by status"
);

Use Cases

Standardize Naming Convention

Rename groups to follow a consistent naming convention:
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:
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:
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 MessageCauseResolution
Group with ID not foundInvalid group IDVerify the group ID exists
Group does not belong to your organizationGroup belongs to a different organizationUse a group ID from your organization
A group with this name already existsDuplicate group nameChoose a different name
Group name is requiredMissing name field in requestProvide a name field
Group name must be between 1 and 255 charactersName is too short or too longUse a name with 1-255 characters
Path parameter groupId does not match bodyMismatch between URL and body group IDsEnsure 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

Authorizations

X-API-KEY
string
header
required

Your API key. This is required by most endpoints to access our API programatically. Reach out to us at [email protected] to get an API key for your use.

Path Parameters

groupId
integer
required

ID of the group to update

Required range: x > 0

Body

application/json
name
string
required
Required string length: 1 - 255

Response

Successful response

id
number
required
name
string
required