# Connections

> Outside APIs, sheets and feeds the site reads from. 7 endpoints in the Unvop API.

Outside APIs, sheets and feeds the site reads from.

## List connections

`GET /v1/sites/{siteId}/connections`

Scope: `connections:read`.

Connections to outside APIs, Google Sheets, Airtable and feeds, with how many collections use each and the last test. Secret values are never returned; secretsSet names the ones that are set.

### Path parameters

- `siteId` (string, required): The site’s id.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `name` (string, required)
  - `kind` (string, required): One of `rest`, `google-sheet`, `airtable`, `rss`.
  - `baseUrl` (string, required)
  - `headers` (map of string, required)
  - `secretsSet` (array of strings, required): The names of secrets that have a value. Secret values are never returned.
- `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).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

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

## Create a connection

`POST /v1/sites/{siteId}/connections`

Scope: `connections:write`.

Connect an outside API, sheet or feed. Secrets are stored encrypted and are write-only. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.

### 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): (up to 80 characters)
- `kind` (string, required): One of `rest`, `google-sheet`, `airtable`, `rss`.
- `baseUrl` (string, required): (up to 2,000 characters)
- `headers` (map of string): Plain headers sent with every request.
- `secrets` (map of string): Secret headers (or apiKey), encrypted at rest and never returned. Send an empty string to remove one; leave one out to keep it.

### Response 201

- `id` (string, required)
- `name` (string, required)
- `kind` (string, required): One of `rest`, `google-sheet`, `airtable`, `rss`.
- `baseUrl` (string, required)
- `headers` (map of string, required)
- `secretsSet` (array of strings, required): The names of secrets that have a value. Secret values are never returned.

### 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.
- `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/sites/site_123/connections \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Bookings API",
    "kind": "rest",
    "baseUrl": "https://api.example.com/v2",
    "secrets": {
      "Authorization": "Bearer sk_live_…"
    }
  }'
```

## Get a connection

`GET /v1/sites/{siteId}/connections/{connectionId}`

Scope: `connections:read`.

One connection, with the collections that use it and its last test. Secret values are never returned.

### Path parameters

- `siteId` (string, required): The site’s id.
- `connectionId` (string, required)

### Response 200

- `id` (string, required)
- `name` (string, required)
- `kind` (string, required): One of `rest`, `google-sheet`, `airtable`, `rss`.
- `baseUrl` (string, required)
- `headers` (map of string, required)
- `secretsSet` (array of strings, required): The names of secrets that have a value. Secret values are never returned.

### 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 https://api.unvop.com/v1/sites/site_123/connections/conn_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change a connection

`PATCH /v1/sites/{siteId}/connections/{connectionId}`

Scope: `connections:write`.

Change a connection. Secrets you send replace those names; secrets you leave out are kept. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `connectionId` (string, required)

### Request body (JSON)

- `name` (string): (up to 80 characters)
- `kind` (string): One of `rest`, `google-sheet`, `airtable`, `rss`.
- `baseUrl` (string): (up to 2,000 characters)
- `headers` (map of string): Plain headers sent with every request.
- `secrets` (map of string): Secret headers (or apiKey), encrypted at rest and never returned. Send an empty string to remove one; leave one out to keep it.

### Response 200

- `id` (string, required)
- `name` (string, required)
- `kind` (string, required): One of `rest`, `google-sheet`, `airtable`, `rss`.
- `baseUrl` (string, required)
- `headers` (map of string, required)
- `secretsSet` (array of strings, required): The names of secrets that have a value. Secret values are never returned.

### 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.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PATCH https://api.unvop.com/v1/sites/site_123/connections/conn_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ana",
    "kind": "rest"
  }'
```

## Delete a connection

`DELETE /v1/sites/{siteId}/connections/{connectionId}`

Scope: `connections:write`.

Delete a connection. Collections that synced from it keep their entries and become manual. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `connectionId` (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/sites/site_123/connections/conn_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Test a connection

`POST /v1/sites/{siteId}/connections/{connectionId}/test`

Scope: `connections:write`.

Call the connection’s base URL and report what came back. The result is kept as its last test.

### Path parameters

- `siteId` (string, required): The site’s id.
- `connectionId` (string, required)

### Response 200

- `ok` (boolean, required)
- `status` (number)
- `sample` (any)
- `error` (string)

### 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 POST https://api.unvop.com/v1/sites/site_123/connections/conn_123/test \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Call a connection

`POST /v1/sites/{siteId}/connections/{connectionId}/request`

Scope: `connections:write`.

Send one request through a connection (its base URL plus path, with its headers and secrets) and see a sample of the answer. Private and local addresses are refused.

### Path parameters

- `siteId` (string, required): The site’s id.
- `connectionId` (string, required)

### Request body (JSON)

- `path` (string): (up to 1,000 characters)
- `method` (string): One of `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`.
- `body` (any)

### Response 200

- `ok` (boolean, required)
- `status` (number)
- `sample` (any)
- `error` (string)

### 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.
- `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/sites/site_123/connections/conn_123/request \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "path": "/menu",
    "method": "GET"
  }'
```
