curl --request GET \
--url https://app.chainpatrol.io/api/v2/organization/asset-groups \
--header 'X-API-KEY: <api-key>'{
"groups": [
{
"id": 123,
"name": "<string>",
"assetCount": 123
}
]
}List all asset groups belonging to your organization with asset counts.
curl --request GET \
--url https://app.chainpatrol.io/api/v2/organization/asset-groups \
--header 'X-API-KEY: <api-key>'{
"groups": [
{
"id": 123,
"name": "<string>",
"assetCount": 123
}
]
}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: "GET",
headers: {
"X-API-KEY": "YOUR_API_KEY_HERE",
},
}
);
const data = await response.json();
console.log(data.groups);
{
"groups": [
{
"id": 1,
"name": "URLs",
"assetCount": 25
},
{
"id": 2,
"name": "Wallets",
"assetCount": 10
},
{
"id": 3,
"name": "Socials",
"assetCount": 15
},
{
"id": 4,
"name": "Empty Group",
"assetCount": 0
}
]
}
| Field | Type | Description |
|---|---|---|
| groups | array | Array of group objects belonging to your organization |
| groups[].id | number | Unique identifier for the group |
| groups[].name | string | Display name of the group |
| groups[].assetCount | number | Number of assets currently assigned to this group |
{
"error": {
"code": "UNAUTHORIZED",
"message": "API key with organization access required"
}
}
async function displayGroupStats() {
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
}
);
const { groups } = await response.json();
console.log("Asset Group Statistics:");
console.log("========================");
groups.forEach((group) => {
console.log(`${group.name}: ${group.assetCount} assets`);
});
const totalAssets = groups.reduce((sum, g) => sum + g.assetCount, 0);
console.log(`\nTotal: ${totalAssets} assets across ${groups.length} groups`);
}
async function findGroupByName(groupName: string) {
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
}
);
const { groups } = await response.json();
const group = groups.find((g) => g.name.toLowerCase() === groupName.toLowerCase());
if (group) {
console.log(`Found group "${group.name}" (ID: ${group.id}) with ${group.assetCount} assets`);
return group;
} else {
console.log(`Group "${groupName}" not found`);
return null;
}
}
// Usage
findGroupByName("Wallets");
async function findEmptyGroups() {
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
}
);
const { groups } = await response.json();
const emptyGroups = groups.filter((g) => g.assetCount === 0);
if (emptyGroups.length > 0) {
console.log(`Found ${emptyGroups.length} empty groups:`);
emptyGroups.forEach((g) => console.log(` - ${g.name} (ID: ${g.id})`));
} else {
console.log("No empty groups found");
}
return emptyGroups;
}
interface GroupOption {
value: number;
label: string;
count: number;
}
async function getGroupOptions(): Promise<GroupOption[]> {
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
}
);
const { groups } = await response.json();
return groups.map((group) => ({
value: group.id,
label: `${group.name} (${group.assetCount})`,
count: group.assetCount,
}));
}
// Usage in a UI framework
async function renderGroupSelector() {
const options = await getGroupOptions();
// Example for React/similar framework
// return (
// <select>
// {options.map(opt => (
// <option key={opt.value} value={opt.value}>
// {opt.label}
// </option>
// ))}
// </select>
// );
}
async function exportGroupSummary() {
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
}
);
const { groups } = await response.json();
// Create CSV content
const csvHeader = "Group ID,Group Name,Asset Count\n";
const csvRows = groups
.map((g) => `${g.id},"${g.name}",${g.assetCount}`)
.join("\n");
const csvContent = csvHeader + csvRows;
// Save to file (Node.js)
const fs = require("fs");
fs.writeFileSync("group-summary.csv", csvContent);
console.log("Group summary exported to group-summary.csv");
}
async function monitorGroupGrowth() {
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": "YOUR_API_KEY_HERE" },
}
);
const { groups } = await response.json();
// Sort by asset count
const sortedGroups = [...groups].sort((a, b) => b.assetCount - a.assetCount);
console.log("Groups by size (largest first):");
sortedGroups.forEach((group, index) => {
const percentage = groups.reduce((sum, g) => sum + g.assetCount, 0);
const groupPercentage = ((group.assetCount / percentage) * 100).toFixed(1);
console.log(
`${index + 1}. ${group.name}: ${group.assetCount} assets (${groupPercentage}%)`
);
});
}
// Create a helper class for group management
class GroupManager {
private apiKey: string;
private cache: Map<number, { name: string; assetCount: number }> = new Map();
private cacheTime: number = 0;
private cacheTTL: number = 5 * 60 * 1000; // 5 minutes
constructor(apiKey: string) {
this.apiKey = apiKey;
}
async getGroups(forceRefresh: boolean = false) {
if (!forceRefresh && Date.now() - this.cacheTime < this.cacheTTL) {
return Array.from(this.cache.values());
}
const response = await fetch(
"https://app.chainpatrol.io/api/v2/organization/asset-groups",
{
headers: { "X-API-KEY": this.apiKey },
}
);
const { groups } = await response.json();
this.cache.clear();
groups.forEach((g) => {
this.cache.set(g.id, { name: g.name, assetCount: g.assetCount });
});
this.cacheTime = Date.now();
return groups;
}
async getGroupName(groupId: number): Promise<string | null> {
if (this.cache.has(groupId)) {
return this.cache.get(groupId)!.name;
}
await this.getGroups();
return this.cache.get(groupId)?.name || null;
}
invalidateCache() {
this.cache.clear();
this.cacheTime = 0;
}
}
// Usage
const manager = new GroupManager("YOUR_API_KEY_HERE");
const groups = await manager.getGroups();
const groupName = await manager.getGroupName(1);
assetCount reflects the current number of assets assigned to each groupYour 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.
Successful response
Show child attributes
Was this page helpful?