# Connect a cloud account

`POST https://evohub.io/api/v1/catalog/connections`

Part of the [Catalog API](https://docs.evohub.io/catalog.md) reference · operationId `createConnection`.

Creates a connection reporting into one environment, in state
`pending`. It is created before access is granted, so you have its
`external_id` for the AWS role's trust policy, or for the Azure tag
or GCP label. Then give the role ARN (AWS), directory id (Azure) or
application credential (portvMind) with a `PATCH`. Leave `regions`
empty to read every region the account has enabled. An organization
may have at most 20 connections.

Requires the `identity:cloudaccount:write` and `catalog:source:write` scopes.

## Authorization

Any one of:

- `bearerKey`
- `headerKey`

Where:

- `bearerKey`: HTTP Bearer — An EvoHub API key (`evohub_…`) as a bearer token.
- `headerKey`: API key in the header `X-API-Key` — An EvoHub API key (`evohub_…`).

## Request body (required)

Content type: `application/json`

Type: `object`

- `provider` (string, required, one of `aws`, `azure`, `gcp`, `vmind`)
- `name` (string, required, max length 100)
- `environment_id` (string, required)
- `role_arn` (string): AWS: `arn:aws:iam::<account>:role/EvoHub…`, no path.
- `tenant_id` (string): Azure: the directory (tenant) id.
- `regions` (array of string, max items 40)

## Responses

### 201 — The cloud account.

Content type: `application/json`

Type: `object`

- `data` (CloudConnection)
  - `id` (string, example `con_7d9f1b3a5c7e9a2c4e6b8d0f2a4c6e8b`)
  - `source_id` (string)
  - `environment_id` (string)
  - `provider` (string, one of `aws`, `azure`, `gcp`, `vmind`)
  - `name` (string)
  - `role_arn` (string)
  - `tenant_id` (string)
  - `credential_id` (string)
  - `has_secret` (boolean)
  - `external_id` (string): Ours, random and unique. Empty without `identity:cloudaccount:write`.
  - `regions` (array of string): Empty means every region the account has enabled.
  - `account_id` (string)
  - `status` (string, one of `pending`, `ok`, `error`, `paused`)
  - `last_error` (string)
  - `denied` (array of string): Services the access did not let it read on the last read. Not a failure.
  - `last_polled_at` (string (date-time) | null)
  - `next_poll_at` (string (date-time))
  - `created_by` (string)
  - `created_at` (string (date-time))
  - `updated_at` (string (date-time))

### 400 — The request is not valid: a field or filter value is wrong (`VALIDATION_ERROR`, with a sentence saying what), the body is not the expected JSON or carries an unknown field (`INVALID_BODY`), the cursor is not one this list gave (`INVALID_CURSOR`), a binding names a service that does not exist (`UNKNOWN_COMPONENT`), or a `PATCH` tries to change a slug (`SLUG_IMMUTABLE`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

### 401 — No API key was sent, or it is unknown, revoked or expired (`UNAUTHORIZED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

### 403 — The key lacks a scope this endpoint needs (`FORBIDDEN`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

### 409 — The name is taken (`NAME_TAKEN`), or the organization has 20 connections (`TOO_MANY_CONNECTIONS`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

### 429 — Too many requests (`RATE_LIMITED`). Wait for `Retry-After` seconds.

Headers:

- `Retry-After` (integer): Seconds to wait before retrying.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

### 500 — Something went wrong on EvoHub's side (`INTERNAL_ERROR`). Retry later.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

### 503 — Cloud accounts for this provider cannot be connected on this EvoHub (`CLOUD_NOT_CONFIGURED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required, example `NOT_FOUND`)
  - `message` (string, required, example `not found`)
  - `request_id` (string)

## Example request

```bash
curl -X POST 'https://evohub.io/api/v1/catalog/connections' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "name": "Production account",
  "regions": [
    "eu-central-1"
  ],
  "provider": "aws",
  "environment_id": "env_2c4e6a8b0d1f3a5c7e9b1d3f5a7c9e0b"
}'
```
