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>"
}Rename an existing 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>"
}X-API-KEY header:
X-API-KEY: your_api_key_here
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);
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | number | Yes | ID of the group to update |
| 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) |
{
"id": 4,
"name": "Renamed Group"
}
| Field | Type | Description |
|---|---|---|
| id | number | Group ID |
| name | string | Updated group name |
{
"error": {
"code": "BAD_REQUEST",
"message": "Group name is required"
}
}
{
"error": {
"code": "BAD_REQUEST",
"message": "Group name must be between 1 and 255 characters"
}
}
{
"error": {
"code": "UNAUTHORIZED",
"message": "API key with organization access required"
}
}
{
"error": {
"code": "FORBIDDEN",
"message": "Group does not belong to your organization"
}
}
{
"error": {
"code": "NOT_FOUND",
"message": "Group with ID 4 not found"
}
}
{
"error": {
"code": "CONFLICT",
"message": "A group with this 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;
}
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}`);
}
});
});
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"
);
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}"`);
}
}
}
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}"`);
}
}
}
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();
});
}
| Error Message | Cause | Resolution |
|---|---|---|
| Group with 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 |
Your API key. This is required by most endpoints to access our API programatically. Reach out to us at support@chainpatrol.io to get an API key for your use.
ID of the group to update
x > 01 - 255Was this page helpful?