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

# Get Top Accounts

> Get the highest-performing accounts by a specific metric

## Endpoint

```
POST https://api.ugc.inc/stats/aggregated/top-accounts
```

## Overview

Get the top N accounts ranked by a specific metric (followers, following, views, or likes). Uses the latest statistics for each account. Perfect for displaying leaderboards and identifying best-performing accounts.

## Request Body

<ParamField body="metric" type="string" required>
  The metric to sort by. One of: `followers`, `following`, `views`, `likes`
</ParamField>

<ParamField body="limit" type="number">
  Number of accounts to return. Default: 5. Maximum: 100.
</ParamField>

<ParamField body="accountIds" type="string[]">
  Array of account IDs to filter. Omit to include all accounts.
</ParamField>

<ParamField body="tag" type="string">
  Filter by account tag
</ParamField>

<ParamField body="org_group" type="string">
  Filter by organization group
</ParamField>

<ParamField body="user_group" type="string">
  Filter by user group
</ParamField>

## Response

<ResponseField name="data" type="TopAccount[]">
  Array of top accounts sorted by the requested metric

  <Expandable title="TopAccount properties">
    <ResponseField name="account_id" type="string">
      Account identifier
    </ResponseField>

    <ResponseField name="username" type="string | null">
      Platform username
    </ResponseField>

    <ResponseField name="nick_name" type="string | null">
      Display name/nickname
    </ResponseField>

    <ResponseField name="pfp_url" type="string | null">
      Profile picture URL
    </ResponseField>

    <ResponseField name="type" type="string">
      Platform type (`tiktok` or `instagram`)
    </ResponseField>

    <ResponseField name="tag" type="string | null">
      Account tag
    </ResponseField>

    <ResponseField name="followers" type="number | null">
      Current follower count
    </ResponseField>

    <ResponseField name="following" type="number | null">
      Current following count
    </ResponseField>

    <ResponseField name="views" type="number | null">
      Total views across all posts
    </ResponseField>

    <ResponseField name="likes" type="number | null">
      Total likes across all posts
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 UTC timestamp (ends in Z) of the stat record
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.ugc.inc/stats/aggregated/top-accounts \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "metric": "followers",
      "limit": 5,
      "tag": "fitness"
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.ugc.inc/stats/aggregated/top-accounts',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'metric': 'followers',
          'limit': 5,
          'tag': 'fitness'
      }
  )

  data = response.json()

  if data['ok']:
      for i, account in enumerate(data['data'], 1):
          print(f"{i}. @{account['username']}: {account['followers']} followers")
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.ugc.inc/stats/aggregated/top-accounts', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      metric: 'followers',
      limit: 5,
      tag: 'fitness'
    })
  });

  const data = await response.json();

  if (data.ok) {
    data.data.forEach((account, index) => {
      console.log(`${index + 1}. @${account.username}: ${account.followers} followers`);
    });
  }
  ```

  ```typescript React theme={null}
  import { UGCClient } from 'ugcinc';

  const client = new UGCClient({
    apiKey: 'YOUR_API_KEY'
  });

  const response = await client.stats.getTopAccounts({
    metric: 'followers',
    limit: 5,
    tag: 'fitness'
  });

  if (response.ok) {
    response.data.forEach((account, index) => {
      console.log(`${index + 1}. @${account.username}:`);
      console.log(`   Followers: ${account.followers}`);
      console.log(`   Views: ${account.views}`);
    });
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "ok": true,
    "code": 200,
    "message": "Success",
    "data": [
      {
        "account_id": "acc_123456",
        "username": "fitness_guru",
        "nick_name": "Fitness Guru",
        "pfp_url": "https://example.com/avatar.jpg",
        "type": "tiktok",
        "tag": "fitness",
        "followers": 125000,
        "following": 342,
        "views": 5600000,
        "likes": 420000,
        "created_at": "2024-01-15T10:00:00Z"
      },
      {
        "account_id": "acc_789012",
        "username": "workout_daily",
        "nick_name": "Daily Workouts",
        "pfp_url": "https://example.com/avatar2.jpg",
        "type": "tiktok",
        "tag": "fitness",
        "followers": 98500,
        "following": 289,
        "views": 3200000,
        "likes": 280000,
        "created_at": "2024-01-15T10:00:00Z"
      }
    ]
  }
  ```
</ResponseExample>
