curl --request POST \
--url https://app.chainpatrol.io/api/v2/organization/asset-groups \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"name": "<string>"
}
'{
"id": 123,
"name": "<string>"
}Create a new asset group for organizing your organization’s assets.
curl --request POST \
--url https://app.chainpatrol.io/api/v2/organization/asset-groups \
--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",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": "YOUR_API_KEY_HERE",
},
body: JSON.stringify({
name: "New Group",
}),
}
);
const data = await response.json();
console.log(data);
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Name for the new group (1-255 characters) |
{
"id": 4,
"name": "New Group"
}
| Field | Type | Description |
|---|---|---|
| id | number | Unique identifier for the group |
| name | string | Name of the created group |
{
"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": "CONFLICT",
"message": "A group with this name already exists"
}
}
// Good examples
await createGroup("Official Websites");
await createGroup("Treasury Wallets");
await createGroup("Social Media Accounts");
await createGroup("Smart Contracts - Production");
await createGroup("Smart Contracts - Testnet");
// Avoid
await createGroup("Group1"); // Not descriptive
await createGroup("Misc"); // Too vague
await createGroup("test"); // Not professional
async function createGroupIfNotExists(groupName: string) {
// Check if group already exists
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() === groupName.toLowerCase()
);
if (existingGroup) {
console.log(`Group "${groupName}" already exists with ID ${existingGroup.id}`);
return existingGroup;
}
// 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: groupName }),
}
);
const newGroup = await createResponse.json();
console.log(`Created new group "${groupName}" with ID ${newGroup.id}`);
return newGroup;
}
async function createMultipleGroups(groupNames: string[]) {
const results = [];
for (const name of groupNames) {
try {
const response = 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 }),
}
);
if (response.ok) {
const group = await response.json();
results.push({ name, success: true, id: group.id });
} else {
const error = await response.json();
results.push({ name, success: false, error: error.error.message });
}
} catch (error) {
results.push({ name, success: false, error: String(error) });
}
}
return results;
}
// Usage
const groupNames = ["Websites", "Wallets", "Social Media", "Contracts"];
createMultipleGroups(groupNames).then((results) => {
const successful = results.filter((r) => r.success).length;
console.log(`Created ${successful} of ${results.length} groups`);
results.forEach((r) => {
if (r.success) {
console.log(`✓ ${r.name} (ID: ${r.id})`);
} else {
console.log(`✗ ${r.name}: ${r.error}`);
}
});
});
async function initializeGroupStructure() {
const standardGroups = [
"Official Websites",
"Documentation Sites",
"Blockchain Addresses",
"Smart Contracts",
"Twitter Accounts",
"Discord Servers",
"Telegram Channels",
"GitHub Repositories",
"Email Addresses",
"Other Assets",
];
console.log("Initializing group structure...");
for (const groupName of standardGroups) {
const response = 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: groupName }),
}
);
if (response.ok) {
const group = await response.json();
console.log(`✓ Created "${groupName}" (ID: ${group.id})`);
} else {
console.log(`✗ Failed to create "${groupName}"`);
}
}
console.log("Group structure initialization complete");
}
async function createProjectGroups(projectName: string) {
const groupTypes = ["URLs", "Wallets", "Contracts", "Socials"];
const groups = [];
for (const type of groupTypes) {
const groupName = `${projectName} - ${type}`;
const response = 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: groupName }),
}
);
if (response.ok) {
const group = await response.json();
groups.push(group);
console.log(`Created group: ${groupName}`);
}
}
return groups;
}
// Usage
createProjectGroups("DeFi Protocol").then((groups) => {
console.log(`Created ${groups.length} groups for project`);
});
async function createEnvironmentGroups() {
const environments = ["Production", "Staging", "Development"];
const categories = ["URLs", "APIs", "Contracts"];
for (const env of environments) {
for (const category of categories) {
const groupName = `${env} - ${category}`;
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: groupName }),
}
);
console.log(`Created: ${groupName}`);
}
}
}
async function ensureGroupForAssetType(assetType: string) {
const groupName = `${assetType} Assets`;
// Check if group exists
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 === groupName);
if (existingGroup) {
return existingGroup.id;
}
// 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: groupName }),
}
);
const newGroup = await createResponse.json();
return newGroup.id;
}
// Usage: Automatically create groups as needed
const urlGroupId = await ensureGroupForAssetType("URL");
const addressGroupId = await ensureGroupForAssetType("ADDRESS");
| Error Message | Cause | Resolution |
|---|---|---|
| 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 |
| A group with this name already exists | Duplicate group name | Use a different name or use existing group |
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.
1 - 255Was this page helpful?