# Your API keys

The calling user’s own API keys in the key’s organisation: status, scopes and today’s calls.

Its operations need the scope `api_access.view`.

**Endpoints**

- `GET/v1/user/api-keys`

## List your API keys

GET/v1/user/api-keys

Lists the API keys the calling user made in the key’s organisation, with their status, permissions and today’s calls; never another user’s keys and never another organisation’s. Filter by status and search text; sorts by one column. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `api_access.view`.

### Query parameters

- `status` (array of strings or null): Only keys in one of these statuses: `active` (live now), `expired` (not revoked, past its expiry) or `revoked`. Absent lists every status. A list: repeat the parameter (`status=active&status=expired`) or send one value (`status=active`); `status[]=active` is accepted too. Values:`active``expired``revoked`(an open set: new values may be added)
- `search` (string or null): Only keys whose name, or the last characters the key shows (`last_four`, or the key’s last four for a newer key), contains this text.
- `sort` (string or null): The column to sort by: `name`, `created_at`, `expires_at` or `last_used_at`; a key that never expires sorts as the far future, and a key never used sorts last in both directions. Without one the newest comes first. Values:`name``created_at``expires_at``last_used_at`(an open set: new values may be added)
- `direction` (string or null): The sort direction, `asc` (the default) or `desc`. Values:`asc``desc`(an open set: new values may be added)
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `include_total` (string or null): Ignored: `total` is always present. Values:`true``false``1``0`(an open set: new values may be added)
- `per_page` (integer or null): How many items one page holds, from 1 to 100; 25 when omitted.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the calling user’s own API keys in the key’s organisation.

Each item of the page:

- `uuid` (string): The UUID of the key.
- `name` (string): The name the key was given when it was made.
- `last_four` (string): Four characters of the key kept to tell keys apart: the four before its six-character checksum, not its last four. `redacted_key` is the form to show. The key itself is shown once, when it is made.
- `redacted_key` (string): The key as the console shows it: the prefix and the key’s last four characters (`wt15ak_…Qz3x`), or, for an older key whose last characters were never kept, the four kept characters followed by six dots for the hidden checksum (`wt15ak_…a1b2••••••`).
- `scopes` (array of strings): The permissions the key carries, as `<module>.<action>` names.
- `status` (string): One of `active` (live now), `expired` (not revoked, past its expiry) or `revoked`. Values:`active``expired``revoked`(an open set: new values may be added)
- `created_at` (integer): Epoch milliseconds. When the key was made. An instant: epoch milliseconds, UTC.
- `expires_at` (integer or null): Epoch milliseconds. When the key expires; null for a key that never expires. An instant: epoch milliseconds, UTC.
- `last_used_at` (integer or null): Epoch milliseconds. When the key last made a call; null when it never did. An instant: epoch milliseconds, UTC.
- `revoked_at` (integer or null): Epoch milliseconds. When the key was revoked; null for a key that was not. An instant: epoch milliseconds, UTC.
- `calls_today` (integer): How many calls the key made today (UTC); 0 for a key that is not active.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/user/api-keys**

curl:

```bash
curl https://rest.watchtower15.com/v1/user/api-keys \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->userApiKeys->list()->autoPaging() as $item) { echo $item->uuid, "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.userApiKeys.list()) {
  console.log(item.uuid);
}
```

Python:

```python
client = Client.from_environment()

for item in client.user_api_keys.list():
    print(item.uuid)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example",
      "last_four": "example",
      "redacted_key": "example",
      "scopes": [
        "example"
      ],
      "status": "active",
      "created_at": 1794214800000,
      "expires_at": 1794214800000,
      "last_used_at": 1794214800000,
      "revoked_at": 1794214800000,
      "calls_today": 1
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the api_access.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

Source: https://developer.watchtower15.com/api/reference/user-api-keys/
