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>"
}
'import requests
url = "https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}"
payload = { "name": "<string>" }
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: '<string>'})
};
fetch('https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}"
payload := strings.NewReader("{\n \"name\": \"<string>\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": 123,
"name": "<string>"
}{
"code": "BAD_REQUEST",
"message": "Invalid input data",
"issues": []
}{
"code": "UNAUTHORIZED",
"message": "Authorization not provided",
"issues": []
}{
"code": "FORBIDDEN",
"message": "Insufficient access",
"issues": []
}{
"code": "NOT_FOUND",
"message": "Not found",
"issues": []
}{
"code": "INTERNAL_SERVER_ERROR",
"message": "Internal server error",
"issues": []
}Grupos de assets de la organización
Actualizar grupo de assets de la organización
Rename an existing asset group.
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>"
}
'import requests
url = "https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}"
payload = { "name": "<string>" }
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: '<string>'})
};
fetch('https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}"
payload := strings.NewReader("{\n \"name\": \"<string>\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.chainpatrol.io/api/v2/organization/asset-groups/{groupId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": 123,
"name": "<string>"
}{
"code": "BAD_REQUEST",
"message": "Invalid input data",
"issues": []
}{
"code": "UNAUTHORIZED",
"message": "Authorization not provided",
"issues": []
}{
"code": "FORBIDDEN",
"message": "Insufficient access",
"issues": []
}{
"code": "NOT_FOUND",
"message": "Not found",
"issues": []
}{
"code": "INTERNAL_SERVER_ERROR",
"message": "Internal server error",
"issues": []
}Descripción general
Cambia el nombre de un grupo de Assets (activos digitales: URL, direcciones, perfiles, apps, etc.) existente. Este endpoint te permite actualizar el nombre visible de un grupo que pertenece a tu organización. Todos los assets asignados a este grupo seguirán asignados después del cambio de nombre.Inicio rápido
Autenticación
Incluye tu clave de API en el encabezadoX-API-KEY:
X-API-KEY: your_api_key_here
Solicitud de ejemplo
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);
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);
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)
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"
}'
Parámetros de ruta
| Parámetro | Tipo | Obligatorio | Descripción |
|---|---|---|---|
| groupId | number | Sí | ID del grupo que se actualiza |
Cuerpo de la solicitud
| Campo | Tipo | Obligatorio | Descripción |
|---|---|---|---|
| groupId | number | Sí | ID del grupo que se actualiza (debe coincidir con el parámetro de ruta) |
| name | string | Sí | Nuevo nombre del grupo (de 1 a 255 caracteres) |
Respuesta
Respuesta exitosa
{
"id": 4,
"name": "Renamed Group"
}
Campos de la respuesta
| Campo | Tipo | Descripción |
|---|---|---|
| id | number | ID del grupo |
| name | string | Nombre actualizado del grupo |
Respuestas de error
400 Bad Request
Se devuelve cuando la solicitud tiene un formato incorrecto o falla la validación:{
"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
Se devuelve cuando la clave de API falta, no es válida o no tiene acceso a la organización:{
"error": {
"code": "UNAUTHORIZED",
"message": "API key with organization access required"
}
}
403 Forbidden
Se devuelve cuando el grupo no pertenece a tu organización:{
"error": {
"code": "FORBIDDEN",
"message": "Group does not belong to your organization"
}
}
404 Not Found
Se devuelve cuando el grupo no existe:{
"error": {
"code": "NOT_FOUND",
"message": "Group with ID 4 not found"
}
}
409 Conflict
Se devuelve cuando ya existe un grupo con el nuevo nombre:{
"error": {
"code": "CONFLICT",
"message": "A group with this name already exists"
}
}
Buenas prácticas
Validación antes de renombrar
Verifica si ya existe un grupo con el nombre de destino: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;
}
Renombrado masivo con prefijo o sufijo
Agrega un prefijo o un sufijo a varios grupos: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}`);
}
});
});
Registro de auditoría
Registra los cambios de nombre de los grupos con fines de auditoría: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"
);
Casos de uso
Estandarizar la convención de nombres
Renombra los grupos para que sigan una convención de nombres uniforme: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}"`);
}
}
}
Migrar la estructura de grupos
Renombra los grupos como parte de una migración de estructura: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}"`);
}
}
}
Renombrado interactivo
Ofrece una interfaz interactiva para renombrar: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();
});
}
Mensajes de error comunes
| Mensaje de error | Causa | Solución |
|---|---|---|
| Group with ID not found | ID de grupo no válido | Verifica que el ID del grupo exista |
| Group does not belong to your organization | El grupo pertenece a otra organización | Usa un ID de grupo de tu organización |
| A group with this name already exists | Nombre de grupo duplicado | Elige un nombre distinto |
| Group name is required | Falta el campo name en la solicitud | Incluye un campo name |
| Group name must be between 1 and 255 characters | El nombre es demasiado corto o demasiado largo | Usa un nombre de 1 a 255 caracteres |
| Path parameter groupId does not match body | Los ID de grupo de la URL y del cuerpo no coinciden | Asegúrate de que ambos ID de grupo coincidan |
Notas
- Los nombres de los grupos deben ser únicos dentro de tu organización
- Los nombres distinguen entre mayúsculas y minúsculas al verificar que sean únicos
- Todos los assets asignados al grupo siguen asignados después del cambio de nombre
- La organización se determina automáticamente a partir de tu clave de API
- El ID del grupo debe coincidir en la ruta de la URL y en el cuerpo de la solicitud
- Renombrar un grupo no afecta las asignaciones de assets ni los metadatos de los assets
- La cantidad de assets del grupo no se ve afectada por las operaciones de renombrado
Autorizaciones
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.
Cuerpo
application/json
¿Esta página le ayudó?