The asset.list method allows you to retrieve bulk lists of assets that ChainPatrol has reviewed, with powerful filtering options by type, status, and date range. This method is ideal for bulk analysis and reporting.

API Reference

Method Signature

client.asset.list(request: AssetListInput): Promise<AssetListOutput>

Parameters

request
AssetListInput
required
The asset list request object with filtering criteria.

Returns

assets
array
required
Array of asset objects matching the filter criteria.

Filtering Options

By Asset Type

Filter by URL, PAGE, or ADDRESS to focus on specific asset categories.

By Status

Filter by BLOCKED, ALLOWED, or UNKNOWN status.

By Date Range

Specify start and end dates to analyze specific time periods.

By Organization

Use organizationSlug to get organization-specific results.

Getting Started

Quick Start

import { ChainPatrolClient } from "@chainpatrol/sdk";

const client = new ChainPatrolClient({
apiKey: "cp_live_your_api_key_here",
});

const result = await client.asset.list({
type: "URL",
status: "BLOCKED",
startDate: "2023-01-01",
endDate: "2023-12-31",
});

console.log(`Found ${result.assets.length} blocked URLs`);

Basic Usage Patterns

// Get recent threats
async function getRecentThreats(days: number = 7) {
  const endDate = new Date().toISOString().split("T")[0];
  const startDate = new Date(Date.now() - days * 24 * 60 * 60 * 1000)
    .toISOString()
    .split("T")[0];

  return await client.asset.list({
    type: "URL",
    status: "BLOCKED",
    startDate,
    endDate,
  });
}

// Count assets by status
async function getAssetStats(dateRange: { start: string; end: string }) {
  const [blocked, allowed] = await Promise.all([
    client.asset.list({
      type: "URL",
      status: "BLOCKED",
      startDate: dateRange.start,
      endDate: dateRange.end,
    }),
    client.asset.list({
      type: "URL",
      status: "ALLOWED",
      startDate: dateRange.start,
      endDate: dateRange.end,
    }),
  ]);

  return {
    blocked: blocked.assets.length,
    allowed: allowed.assets.length,
  };
}

Implementation Guide

Use Cases & Patterns

Bulk Analysis

async function analyzeThreats(timeRange: { start: string; end: string }) {
  const [blockedUrls, blockedAddresses, allowedUrls] = await Promise.all([
    client.asset.list({
      type: "URL",
      status: "BLOCKED",
      startDate: timeRange.start,
      endDate: timeRange.end,
    }),
    client.asset.list({
      type: "ADDRESS",
      status: "BLOCKED",
      startDate: timeRange.start,
      endDate: timeRange.end,
    }),
    client.asset.list({
      type: "URL",
      status: "ALLOWED",
      startDate: timeRange.start,
      endDate: timeRange.end,
    }),
  ]);

  return {
    blockedUrls: blockedUrls.assets.length,
    blockedAddresses: blockedAddresses.assets.length,
    allowedUrls: allowedUrls.assets.length,
  };
}

Data Export & Processing

async function exportThreats(outputFormat: "csv" | "json" = "json") {
  const threats = await client.asset.list({
    type: "URL",
    status: "BLOCKED",
    startDate: "2024-01-01",
    endDate: "2024-12-31",
  });

  const processedData = threats.assets.map((asset) => ({
    url: asset.content,
    status: asset.status,
    lastUpdated: asset.updatedAt,
  }));

  if (outputFormat === "csv") {
    // Convert to CSV format
    const headers = Object.keys(processedData[0]).join(",");
    const rows = processedData.map((row) => Object.values(row).join(","));
    return [headers, ...rows].join("\n");
  }

  return processedData;
}

Technical Details

Format Requirements

Date Format Requirements - Dates must be in YYYY-MM-DD format - endDate must be greater than or equal to startDate - Maximum date range may be limited depending on your plan

Error Handling

import { ChainPatrolClientError } from "@chainpatrol/sdk";

try {
  const result = await client.asset.list({
    type: "URL",
    status: "BLOCKED",
    startDate: "2024-01-01",
    endDate: "2024-01-31",
  });
} catch (error) {
  if (error instanceof ChainPatrolClientError) {
    console.error("API Error:", error.message);
  } else {
    console.error("Unexpected error:", error);
  }
}

Rate Limits & Performance

Rate Limits - Paginated requests: Up to 5 requests per second - Results are paginated for large datasets - Consider caching results for frequently accessed data
Performance Tips - Use specific date ranges to limit response size - Cache results when possible to reduce API calls - Consider pagination for very large datasets

Additional Documentation