# Create a database connection

`POST /api/v1/database-connections`

A database on one of the client's servers, for database plans to dump and restore. The password is stored encrypted and never returned.

## Body Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| server_id | integer | yes | The server whose agent dumps and restores the database. Example: `12`. |
| label | string | yes | A name for the connection, shown when choosing one for a plan. Example: `Shop database`. |
| driver | string | yes | The database engine: `mysql` or `pgsql`. One of: `mysql`, `pgsql`. Example: `mysql`. |
| host | string | yes | The database host, as the server's agent reaches it. Example: `db.example.com`. |
| port | integer | no | The database port. Default 3306. Example: `3306`. |
| database | string | yes | The name of the database. Example: `shop`. |
| username | string | yes | The user to connect as. Example: `shop_backup`. |
| password | string | no | The password of `username`, stored encrypted and never returned. Nullable. Example: `<database-password>`. |

## Response

### 201

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| data | object | yes |  |
| data.id | integer | yes |  |
| data.server_id | integer | yes |  |
| data.label | string | yes |  |
| data.driver | string | yes | One of: `mysql`, `pgsql`. |
| data.driver_label | string | yes | One of: `MySQL`, `PostgreSQL`. |
| data.host | string | yes |  |
| data.port | integer | yes |  |
| data.database | string | yes |  |
| data.username | string | yes |  |
| data.has_password | boolean | yes |  |
| data.created_at | string · date-time | yes | Nullable. |
| data.updated_at | string · date-time | yes | Nullable. |

### 401

The request carries no valid token: the `Authorization: Bearer` header is missing, or its token is unknown, revoked or past its expiry date. Send a current personal access token.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | Always `Unauthenticated.`. |

### 403

The token may not do this. The `message` says why: `This token lacks the required ability.` (a `read` token), `Your role does not permit this action.` (its owner is not an Admin or Operator in the client), `This account is disabled.`, `This token is not bound to a client you belong to.`, or `Client suspended`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | What went wrong. |

### 422

The body or the query is invalid. `message` names the first problem and `errors` lists every problem by field.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | The first problem, and how many more there are. |
| errors | object | yes | Every problem, by field. |

### 429

More than 120 requests a minute for this user. Wait the seconds in `Retry-After`, then retry.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| message | string | yes | What went wrong. |

## Request example

```bash
curl -X POST 'https://app.clokeep.com/api/v1/database-connections' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "server_id": 12,
    "label": "Shop database",
    "driver": "mysql",
    "host": "db.example.com",
    "port": 3306,
    "database": "shop",
    "username": "shop_backup",
    "password": "<database-password>"
  }'
```

## Response example (201)

```json
{
  "data": {
    "id": 9,
    "server_id": 12,
    "label": "Shop database",
    "driver": "mysql",
    "driver_label": "MySQL",
    "host": "db.example.com",
    "port": 3306,
    "database": "shop",
    "username": "shop_backup",
    "has_password": true,
    "created_at": "2026-11-01T09:14:22+00:00",
    "updated_at": "2026-11-18T16:40:05+00:00"
  }
}
```

## Response example (401)

```json
{
  "message": "Unauthenticated."
}
```

## Response example (403)

```json
{
  "message": "This token lacks the required ability."
}
```

## Response example (422)

```json
{
  "message": "The server id field is required.",
  "errors": {
    "server_id": [
      "The server id field is required."
    ]
  }
}
```

## Response example (429)

```json
{
  "message": "Too Many Attempts."
}
```
