> ## Documentation Index
> Fetch the complete documentation index at: https://chainpatrol.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Organization Metrics (Deprecated)

> Get public metrics for one or more organizations

<Warning>
  **This endpoint is deprecated.** Please use the new RESTful endpoint [GET /organization/metrics](/external-api/organization-metrics-list) instead. This endpoint will be removed in a future version.
</Warning>

## Quick Start

### Authentication

Include your API key in the `Authorization` header:

```bash theme={null}
Authorization: Bearer your_api_key
```

### Example Request

```bash theme={null}
curl -X POST 'https://api.chainpatrol.io/public/getOrganizationMetrics' \
  -H 'Authorization: Bearer your_api_key' \
  -H 'Content-Type: application/json' \
  -d '{
    "organizationSlug": "your-org",
    "startDate": "2024-01-01T00:00:00Z",
    "endDate": "2024-03-01T00:00:00Z"
  }'
```

## Access Control

The API enforces strict access control based on your API key type:

1. **Organization API Keys**:

   * Can only access metrics for their associated organization
   * Must match the `organizationSlug` exactly
   * Example: An API key for "acme-org" can only query metrics for "acme-org"

2. **User API Keys**:
   * Can access metrics for any organization where the user is a member
   * Requires the user to be an active member of the queried organization
   * Example: A user who is a member of both "acme-org" and "beta-org" can query metrics for both organizations

If you attempt to query an organization without proper permissions, you will receive a 403 Forbidden error with the message: "You do not have permission to access metrics for this organization"

## Example Implementation

<CodeGroup>
  ```javascript JavaScript theme={null}
  async function fetchOrganizationMetrics(organizationSlug, startDate, endDate) {
    const response = await fetch(
      "https://api.chainpatrol.io/public/getOrganizationMetrics",
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer YOUR_API_KEY_HERE",
        },
        body: JSON.stringify({
          organizationSlug,
          startDate,
          endDate,
        }),
      }
    );
    return response.json();
  }

  // Example usage
  fetchOrganizationMetrics(
    "your-org",
    "2024-01-01T00:00:00Z",
    "2024-03-01T00:00:00Z"
  )
    .then((data) => console.log("Metrics:", data))
    .catch((error) => console.error("Error fetching metrics:", error));
  ```

  ```typescript TypeScript theme={null}
  interface OrganizationMetrics {
    metrics: {
      reportsCount: number;
      threatsBlockedCount: number;
      threatsBlockedByAssetType: Array<{
        assetType: string;
        count: number;
      }>;
      domainsBlockedCount: number;
      totalTakedownsFiledCount: number;
      totalTakedownsCompletedCount: number;
      totalDetections: number;
    };
  }

  async function fetchOrganizationMetrics(
    organizationSlug: string,
    startDate?: string,
    endDate?: string
  ): Promise<OrganizationMetrics> {
    const response = await fetch(
      "https://api.chainpatrol.io/public/getOrganizationMetrics",
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer YOUR_API_KEY_HERE",
        },
        body: JSON.stringify({
          organizationSlug,
          startDate,
          endDate,
        }),
      }
    );
    return response.json();
  }

  // Example usage
  fetchOrganizationMetrics(
    "your-org",
    "2024-01-01T00:00:00Z",
    "2024-03-01T00:00:00Z"
  )
    .then((data) => console.log("Metrics:", data))
    .catch((error) => console.error("Error fetching metrics:", error));
  ```

  ```python Python theme={null}
  import requests
  from typing import Dict, Optional
  from datetime import datetime

  def fetch_organization_metrics(
      organization_slug: str,
      start_date: Optional[str] = None,
      end_date: Optional[str] = None
  ) -> Dict:
      response = requests.post(
          "https://api.chainpatrol.io/public/getOrganizationMetrics",
          headers={
              "Content-Type": "application/json",
              "Authorization": "Bearer YOUR_API_KEY_HERE",
          },
          json={
              "organizationSlug": organization_slug,
              "startDate": start_date,
              "endDate": end_date,
          },
      )
      return response.json()

  # Example usage
  try:
      metrics = fetch_organization_metrics(
          "your-org",
          "2024-01-01T00:00:00Z",
          "2024-03-01T00:00:00Z"
      )
      print("Metrics:", metrics)
  except Exception as error:
      print("Error fetching metrics:", str(error))
  ```
</CodeGroup>

## API Details

### Request Parameters

| Parameter        | Type   | Required | Description                                  |
| ---------------- | ------ | -------- | -------------------------------------------- |
| organizationSlug | string | Yes      | Organization slug to query                   |
| startDate        | Date   | No       | Start date for metrics (default: all time)   |
| endDate          | Date   | No       | End date for metrics (default: current date) |

### Response Format

```typescript theme={null}
{
  metrics: {
    reportsCount: number; // Total number of reports
    threatsBlockedCount: number; // Total number of threats blocked
    threatsBlockedByAssetType: Array<{
      // Threats blocked grouped by asset type
      assetType: string;
      count: number;
    }>;
    domainsBlockedCount: number; // Number of domains blocked
    totalTakedownsFiledCount: number; // Total number of takedowns filed
    totalTakedownsCompletedCount: number; // Total number of completed takedowns
    totalDetections: number; // Total number of threat detections
  }
}
```

## Error Handling

| Status Code               | Description                                                          |
| ------------------------- | -------------------------------------------------------------------- |
| 401 Unauthorized          | Invalid or missing API key                                           |
| 403 Forbidden             | API key does not have permission to query the requested organization |
| 500 Internal Server Error | Server error occurred while processing the request                   |

## Notes

* If no date range is provided, metrics will be returned for all time
* The API only returns metrics for a single organization per request
* Organization API keys can only access metrics for their associated organization
* User API keys can access metrics for any organization where the user is a member
* To query multiple organizations, you must use a user API key and ensure the user is a member of all organizations you wish to query


## OpenAPI

````yaml POST /public/getOrganizationMetrics
openapi: 3.0.3
info:
  title: ChainPatrol External API - OpenAPI 3.0
  description: ChainPatrol External API documentation
  version: 2.0.0
servers:
  - url: https://app.chainpatrol.io/api/v2
security: []
tags:
  - name: asset
  - name: report
externalDocs:
  url: https://chainpatrol.com/docs
paths:
  /public/getOrganizationMetrics:
    post:
      tags:
        - public
      summary: Get public metrics for organizations
      description: Get public metrics for one or more organizations
      operationId: getPublicOrganizationMetrics
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                organizationSlug:
                  type: string
                brandSlug:
                  type: string
                startDate:
                  type: string
                endDate:
                  type: string
              required:
                - organizationSlug
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  metrics:
                    type: object
                    properties:
                      reports:
                        type: number
                      newThreats:
                        type: number
                      threatsWatchlisted:
                        type: number
                      takedownsFiled:
                        type: number
                      takedownsCompleted:
                        type: number
                      domainThreats:
                        type: number
                      twitterThreats:
                        type: number
                      telegramThreats:
                        type: number
                      otherThreats:
                        type: number
                    required:
                      - reports
                      - newThreats
                      - threatsWatchlisted
                      - takedownsFiled
                      - takedownsCompleted
                      - domainThreats
                      - twitterThreats
                      - telegramThreats
                      - otherThreats
                  blockedByType:
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                        count:
                          type: number
                      required:
                        - type
                        - count
                  blockedByDay:
                    type: array
                    items:
                      type: object
                      properties:
                        date:
                          type: string
                        count:
                          type: number
                      required:
                        - date
                        - count
                required:
                  - metrics
                  - blockedByType
                  - blockedByDay
        '400':
          description: Invalid input data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BAD_REQUEST'
        '401':
          description: Authorization not provided
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.UNAUTHORIZED'
        '403':
          description: Insufficient access
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.FORBIDDEN'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.INTERNAL_SERVER_ERROR'
      security:
        - ApiKey: []
components:
  schemas:
    error.BAD_REQUEST:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Invalid input data
        code:
          type: string
          description: The error code
          example: BAD_REQUEST
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Invalid input data error (400)
      description: The error information
      example:
        code: BAD_REQUEST
        message: Invalid input data
        issues: []
    error.UNAUTHORIZED:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Authorization not provided
        code:
          type: string
          description: The error code
          example: UNAUTHORIZED
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Authorization not provided error (401)
      description: The error information
      example:
        code: UNAUTHORIZED
        message: Authorization not provided
        issues: []
    error.FORBIDDEN:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Insufficient access
        code:
          type: string
          description: The error code
          example: FORBIDDEN
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Insufficient access error (403)
      description: The error information
      example:
        code: FORBIDDEN
        message: Insufficient access
        issues: []
    error.INTERNAL_SERVER_ERROR:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Internal server error
        code:
          type: string
          description: The error code
          example: INTERNAL_SERVER_ERROR
        issues:
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
          description: An array of issues that were responsible for the error
          example: []
      required:
        - message
        - code
      title: Internal server error error (500)
      description: The error information
      example:
        code: INTERNAL_SERVER_ERROR
        message: Internal server error
        issues: []
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: X-API-KEY
      description: >-
        Your API key. This is required by most endpoints to access our API
        programatically. Reach out to us at
        [support@chainpatrol.io](mailto:support@chainpatrol.io?subject=Re:%20API%20Key%20for%20SDK&body=Company:%20%0AName:%20%0APurpose:%20)
        to get an API key for your use.

````