# Keys

> Platform API keys. 3 endpoints in the Unvop API.

Platform API keys.

## List API keys

`GET /v1/keys`

Scope: `keys:write`.

Every API key that hasn’t been revoked: platform, account and site keys. Needs a platform key.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `name` (string, required)
  - `prefix` (string, required): The public part shown in the dashboard.
  - `kind` (string, required): One of `site`, `platform`, `account`.
  - `scopes` (array of strings, required)
  - `siteId` (string, required, nullable)
  - `siteIds` (array of strings, required, nullable)
  - `createdAt` (string, required): An ISO 8601 timestamp.
  - `lastUsedAt` (string, required, nullable): An ISO 8601 timestamp.
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/keys \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Create an API key

`POST /v1/keys`

Scope: `keys:write`.

Make a key. The key itself is returned once, in key; store it safely. Needs a platform key.

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (JSON)

- `name` (string, required): (at least 1 characters; up to 120 characters)
- `kind` (string, required): platform: every site. site: one site (siteId). account: acts as the account that made the key. One of `platform`, `site`, `account`.
- `siteId` (string)
- `siteIds` (array of strings): Account keys: limit to these sites. (up to 200 items)
- `scopes` (array of strings): One of `sites:write`, `content:read`, `content:write`, `contacts:read`, `generate`, `contacts:write`, `media:write`, `design:write`, `payments:read`, `workflows:read`, `workflows:write`, `tools:read`, `tools:write`, `connections:read`, `connections:write`, `settings:write`, `keys:write`, `analytics:read`.

### Response 201

- `key` (string, required)
- `item` (object, required): An API key, without its secret.
  - `id` (string, required)
  - `name` (string, required)
  - `prefix` (string, required): The public part shown in the dashboard.
  - `kind` (string, required): One of `site`, `platform`, `account`.
  - `scopes` (array of strings, required)
  - `siteId` (string, required, nullable)
  - `siteIds` (array of strings, required, nullable)
  - `createdAt` (string, required): An ISO 8601 timestamp.
  - `lastUsedAt` (string, required, nullable): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/keys \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Ana",
    "kind": "platform"
  }'
```

## Revoke an API key

`DELETE /v1/keys/{keyId}`

Scope: `keys:write`.

Revoke a key. Requests with it fail from now on. Needs a platform key.

### Path parameters

- `keyId` (string, required)

### Response 200

- `ok` (true, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/keys/key_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```
