# Use Takaro data in your own app

Read online players, currency, playtime and leaderboards from the Takaro API for a website, launcher or Discord bot, and keep your API key safe.

You can read your community's data from Takaro and show it anywhere: a website, a launcher, a Discord bot or a status board. This guide covers the common reads and, more importantly, how to do it without leaking your key.

You need an API key first. See [API](/docs/advanced/api#authentication) and [Settings and account](/docs/settings-and-account#api-keys). The examples read it from `TAKARO_API_KEY`.

:::tip[Using an AI assistant to write this?]
Give it `https://api.takaro.io/openapi.json` or the [API reference](/api). Without it, assistants guess paths and get `404`.
:::

## Keep your key safe

:::danger
A **personal key acts as you, with your admin rights.** Anyone who has it can do what you can do in your community. Never put it in anything you hand out: a launcher, a mod, a mobile app, or a website whose code runs in the visitor's browser. Anyone can extract it.
:::

Pick one of these:

1. **Call Takaro from your own small backend** (recommended). Your website or launcher calls your server, and your server calls Takaro with the key. The key never leaves your server.
2. **Use a domain key with a read-only role.** Create a role that only has `READ_PLAYERS`, then create a [domain key](/docs/settings-and-account#api-keys) with only that role. Add a **scope** of `READ_PLAYERS` and an **IP allowlist** of your server's address. If it leaks, it can read player data from that address and nothing else.

Even with option 2, only call Takaro from a server you control. For a public page, have your backend fetch the data every minute or so and serve a cached copy.

## Find your game server ID

Player data is per game server. You identify a server by its Takaro **UUID**, not by its IP address and port. List your servers:

```sh
curl -X POST https://api.takaro.io/gameserver/search \
  -H "Authorization: Bearer $TAKARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Each result has an `id` and a `name`. You can also copy the ID from the URL when you open the server in the dashboard.

## Read player data

`POST /gameserver/player/search` returns one record per player on a server. It needs the `READ_PLAYERS` permission. Each record includes `currency`, `playtimeSeconds`, `online`, `lastSeen`, `ping` and the player's position.

### Who is online

```sh
curl -X POST https://api.takaro.io/gameserver/player/search \
  -H "Authorization: Bearer $TAKARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": { "gameServerId": ["<game-server-id>"], "online": [true] },
    "extend": ["player"],
    "limit": 100
  }'
```

`extend: ["player"]` adds the player's name and platform IDs to each record. Without it you only get IDs.

### Currency and playtime

The same request answers both. Drop the `online` filter to include players who are offline, and read `currency` and `playtimeSeconds` (in seconds) from each record:

```sh
curl -X POST https://api.takaro.io/gameserver/player/search \
  -H "Authorization: Bearer $TAKARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": { "gameServerId": ["<game-server-id>"] },
    "extend": ["player"],
    "limit": 100
  }'
```

### Leaderboard

Sort by currency, highest first. Use `"playtimeSeconds"` for a playtime board.

```sh
curl -X POST https://api.takaro.io/gameserver/player/search \
  -H "Authorization: Bearer $TAKARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": { "gameServerId": ["<game-server-id>"] },
    "extend": ["player"],
    "sortBy": "currency",
    "sortDirection": "desc",
    "limit": 10
  }'
```

### One player

```sh
curl https://api.takaro.io/gameserver/<game-server-id>/player/<player-id> \
  -H "Authorization: Bearer $TAKARO_API_KEY"
```

`<player-id>` is the player's Takaro ID, which you can get from the search above.

For more than 100 players, page through results with `page` and `limit`. See [Querying data](/docs/advanced/api#querying-data).

## Next steps

- [API](/docs/advanced/api) explains keys, scope and errors.
- The [API reference](/api) lists every operation, with the permission each one needs.
