# Connections

> List the apps your workspace is connected to, connect an app with an API key or other credentials, test a connection, remove one, and find out how an app connects.

Web page: https://docs.lodol.com/docs/api/connections

A connection is one account or saved key for an app: the workspace's Stripe key, or someone's own Gmail. A key sees the connections the member who created it can use, as they see them on the **Apps** page, and never their credentials.

The connection endpoints need their own scopes, `connections:read` and `connections:write`, which only API keys can hold: tick **See connected apps** or **Connect and remove apps** when you create the key. See [Scopes](https://docs.lodol.com/docs/api/authentication.md#scopes).

## The connection object

```json
{
  "id": "66a2c4e6f8a0b2c4d6e8f0a1",
  "app_id": "stripe",
  "app_name": "Stripe",
  "name": "Live key",
  "status": "connected",
  "sharing": "workspace",
  "in_use": true,
  "connected_by": { "id": "665f1a2b3c4d5e6f7a8b9c0e", "name": "Ada Lovelace" },
  "last_test": null,
  "expires_at": null,
  "created_at": "2026-10-20T15:02:11+00:00",
  "updated_at": "2026-10-20T15:02:11+00:00"
}
```

<Fields title="Fields">
<Field id="id" type="string" description="The connection's ID." />
<Field id="app_id" type="string" description="The ID of the app it connects, such as stripe. GET /apps/:app_id says how that app connects." />
<Field id="app_name" type="string" description="The app's name, as Lodol shows it." />
<Field id="name" type="string" description="The connection's name, as the Apps page shows it." />
<Field id="status" type="string" description="connected; needs_sign_in, for one that was added but never signed in to, or whose sign-in has lapsed; or failing." />
<Field id="sharing" type="string" description="Whose runs can use it: personal (only the member who connected it), workspace (everyone's), or roles (members with the roles chosen on the Apps page)." />
<Field id="in_use" type="boolean" description="Whether it's the connection the key's member's runs use for this app. A workspace can have several connections to one app." />
<Field id="connected_by" type="object or null" description="The member who added it: their id and name." />
<Field id="last_test" type="object or null" description="What the last test of it found, or null if it hasn't been tested. outcome is working, failed, or unknown for an app with no safe way to test an account; message says it in words; tested_at is when, in ISO 8601." />
<Field id="expires_at" type="string or null" description="When the connection stops working, in ISO 8601, for an app whose sign-in expires; otherwise null." />
<Field id="created_at" type="string or null" description="When it was added, in ISO 8601." />
<Field id="updated_at" type="string or null" description="When it was last changed, in ISO 8601." />
</Fields>

---

## List connections

<Endpoint method="GET" path="/api/v1/connections" />

Returns the connections the member who created the key can use, newest first. A teammate's personal connection isn't listed. Requires the `connections:read` scope.

<Fields title="Query parameters">
<Field id="app_id" type="string" description="Only connections to this app, such as stripe." />
<Field id="limit" type="integer" description="How many to return, from 1 to 100." facts="Default: `50`." />
<Field id="cursor" type="string" description="For the next page: the next_cursor of the page you have." />
</Fields>

```bash tab="cURL" tab-group="lang"
curl "https://api-prod.lodol.com/api/v1/connections?app_id=stripe" \
  -H "Authorization: Bearer $LODOL_API_KEY"
```

```js tab="JavaScript"
const response = await fetch('https://api-prod.lodol.com/api/v1/connections?app_id=stripe', {
  headers: { Authorization: `Bearer ${process.env.LODOL_API_KEY}` },
});
const { connections } = await response.json();
```

```python tab="Python"
response = requests.get(
    "https://api-prod.lodol.com/api/v1/connections",
    headers={"Authorization": f"Bearer {os.environ['LODOL_API_KEY']}"},
    params={"app_id": "stripe"},
)
connections = response.json()["connections"]
```

**Response `200`:** the [connection objects](#the-connection-object). Here the member has a personal Stripe key and can use the workspace's; their runs use their own, so it's the one `in_use`:

```json
{
  "connections": [
    {
      "id": "66a2c4e6f8a0b2c4d6e8f0a2",
      "app_id": "stripe",
      "app_name": "Stripe",
      "name": "Test mode key",
      "status": "connected",
      "sharing": "personal",
      "in_use": true,
      "connected_by": { "id": "665f1a2b3c4d5e6f7a8b9c0e", "name": "Ada Lovelace" },
      "last_test": null,
      "expires_at": null,
      "created_at": "2026-11-01T11:30:00+00:00",
      "updated_at": "2026-11-01T11:30:00+00:00"
    },
    {
      "id": "66a2c4e6f8a0b2c4d6e8f0a1",
      "app_id": "stripe",
      "app_name": "Stripe",
      "name": "Live key",
      "status": "connected",
      "sharing": "workspace",
      "in_use": false,
      "connected_by": { "id": "665f1a2b3c4d5e6f7a8b9c0f", "name": "Grace Hopper" },
      "last_test": null,
      "expires_at": null,
      "created_at": "2026-10-20T15:02:11+00:00",
      "updated_at": "2026-10-20T15:02:11+00:00"
    }
  ],
  "next_cursor": null
}
```

---

## Get a connection

<Endpoint method="GET" path="/api/v1/connections/:id" />

Returns one [connection object](#the-connection-object). Requires the `connections:read` scope. A connection that doesn't exist, or that the key's member can't use, such as a teammate's personal one, returns `404` with the code `not_found`.

```bash
curl https://api-prod.lodol.com/api/v1/connections/66a2c4e6f8a0b2c4d6e8f0a1 \
  -H "Authorization: Bearer $LODOL_API_KEY"
```

---

## How an app connects

<Endpoint method="GET" path="/api/v1/apps/:app_id" />

Says how an app connects, and for one that takes credentials, which ones to send to [Connect an app](#connect-an-app). Any valid key can call it; it needs no scope. `:app_id` is the app's ID, which [Search apps](https://docs.lodol.com/docs/api/catalog.md#search-apps) finds.

```bash
curl https://api-prod.lodol.com/api/v1/apps/slack \
  -H "Authorization: Bearer $LODOL_API_KEY"
```

**Response `200`:**

```json
{
  "id": "slack",
  "name": "Slack",
  "description": "Send messages, share files and manage channels in Slack.",
  "connects": "with_credentials",
  "credentials": [
    { "id": "botToken", "label": "Bot User OAuth Token", "required": true, "hint": "" },
    {
      "id": "signingSecret",
      "label": "Signing Secret",
      "required": false,
      "hint": "For instant triggers. It's under **Basic Information > App Credentials** in your Slack app."
    }
  ]
}
```

<Fields title="Fields">
<Field id="id" type="string" description="The app's ID." />
<Field id="name" type="string" description="The app's name." />
<Field id="description" type="string" description="What Lodol can do with it." />
<Field id="connects" type="string" description="with_credentials, for an app you connect through this API; or by_signing_in, for one you connect by signing in to it in a browser, on the Apps page." />
<Field id="credentials" type="array" description="For an app that connects with credentials, the fields to send in credentials, each with its id, the label the Apps page shows, whether it's required, and a hint. A field with a fixed set of choices has options too. Empty for an app you sign in to, and for one that needs no credentials." />
<Field id="connect_url" type="string" description="For an app you sign in to: the Apps page, where to connect it." />
</Fields>

An app you connect by signing in, such as Gmail, has no credentials to send:

```json
{
  "id": "gmail",
  "name": "Gmail",
  "description": "Send, read, and manage email from your Gmail account.",
  "connects": "by_signing_in",
  "credentials": [],
  "connect_url": "https://app.lodol.com/apps"
}
```

An app the workspace doesn't have returns `404` with the code `not_found`.

---

## Connect an app

<Endpoint method="POST" path="/api/v1/connections" />

Connects an app with an API key or other credentials, as connecting it on the **Apps** page does. Requires the `connections:write` scope. The member who created the key must be allowed to add it: a personal connection needs the **Run workflows** role permission, and one shared with the workspace needs **Manage apps**; otherwise the request gets `403` with the code `permission_denied`.

It always adds a new connection, even when the app already has one: it never replaces a connection. To replace one, connect the new one, then [remove](#remove-a-connection) the old.

Before anything is saved, Lodol asks the app whether it accepts the credentials. If the app turns them down, the request gets `400` with the code `credentials_rejected` and nothing is saved. If the app can't be asked, or doesn't answer clearly, the connection is saved. An app you connect by signing in can't be connected through the API: the request gets `400` with the code `connect_in_browser`, and `connect_url` in the body gives the address of the **Apps** page, where a person connects it.

<Fields title="Headers">
<Field id="Idempotency-Key" type="string" description="Makes the request safe to retry: a repeat with the same key returns the first response instead of adding another connection. See Idempotency." />
</Fields>

<Fields title="Body">
<Field id="app_id" type="string" description="The ID of the app to connect, such as stripe." facts="Required." />
<Field id="credentials" type="object" description="The app's credentials, by the field IDs How an app connects lists, such as secretKey for Stripe. Every required field needs a value." />
<Field id="name" type="string" description="What to call the connection. Left out, Lodol names it." />
<Field id="sharing" type="string" description="personal, so only the member who created the key runs with it, or workspace, so everyone's runs can. To share it with particular roles, change it on the Apps page." />
</Fields>

Any other field is refused with `400`.

```bash tab="cURL" tab-group="lang"
curl -X POST https://api-prod.lodol.com/api/v1/connections \
  -H "Authorization: Bearer $LODOL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: connect-stripe-live" \
  -d '{
    "app_id": "stripe",
    "credentials": { "secretKey": "'"$STRIPE_SECRET_KEY"'" },
    "name": "Live key",
    "sharing": "workspace"
  }'
```

```js tab="JavaScript"
const response = await fetch('https://api-prod.lodol.com/api/v1/connections', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.LODOL_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': 'connect-stripe-live',
  },
  body: JSON.stringify({
    app_id: 'stripe',
    credentials: { secretKey: process.env.STRIPE_SECRET_KEY },
    name: 'Live key',
    sharing: 'workspace',
  }),
});
const connection = await response.json();
```

```python tab="Python"
response = requests.post(
    "https://api-prod.lodol.com/api/v1/connections",
    headers={
        "Authorization": f"Bearer {os.environ['LODOL_API_KEY']}",
        "Idempotency-Key": "connect-stripe-live",
    },
    json={
        "app_id": "stripe",
        "credentials": {"secretKey": os.environ["STRIPE_SECRET_KEY"]},
        "name": "Live key",
        "sharing": "workspace",
    },
)
connection = response.json()
```

**Response `201`:** the new [connection object](#the-connection-object).

```json
{
  "id": "66a2c4e6f8a0b2c4d6e8f0a1",
  "app_id": "stripe",
  "app_name": "Stripe",
  "name": "Live key",
  "status": "connected",
  "sharing": "workspace",
  "in_use": true,
  "connected_by": { "id": "665f1a2b3c4d5e6f7a8b9c0e", "name": "Ada Lovelace" },
  "last_test": null,
  "expires_at": null,
  "created_at": "2026-10-20T15:02:11+00:00",
  "updated_at": "2026-10-20T15:02:11+00:00"
}
```

**Response `400`,** when the app turns the credentials down:

```json
{
  "error": "Stripe didn't accept these credentials: Stripe rejected this key. Nothing was saved.",
  "error_code": "credentials_rejected"
}
```

A required credential left out gets `400` with the code `invalid_request` and a message naming it:

```json
{
  "error": "Stripe needs \"secretKey\" (API key) in \"credentials\". Nothing was saved.",
  "error_code": "invalid_request"
}
```

---

## Test a connection

<Endpoint method="POST" path="/api/v1/connections/:id/test" />

Asks the app whether it still accepts the connection, as **Test connection** on the **Apps** page does, and records the answer. The test only reads: it changes nothing in the app. Requires the `connections:read` scope.

```bash
curl -X POST https://api-prod.lodol.com/api/v1/connections/66a2c4e6f8a0b2c4d6e8f0a1/test \
  -H "Authorization: Bearer $LODOL_API_KEY"
```

**Response `200`:** the [connection object](#the-connection-object), with the result in `last_test`. An app that has no safe way to test an account answers `unknown`:

```json
{
  "id": "66a2c4e6f8a0b2c4d6e8f0a3",
  "app_id": "alienvault_otx",
  "app_name": "AlienVault OTX",
  "name": "Threat lookups",
  "status": "connected",
  "sharing": "personal",
  "in_use": true,
  "connected_by": { "id": "665f1a2b3c4d5e6f7a8b9c0e", "name": "Ada Lovelace" },
  "last_test": {
    "outcome": "unknown",
    "message": "AlienVault OTX has no safe way to test an account. It will be checked the next time a workflow uses it.",
    "tested_at": "2026-11-30T20:01:14.754000+00:00"
  },
  "expires_at": null,
  "created_at": "2026-11-30T20:01:09.808000+00:00",
  "updated_at": "2026-11-30T20:01:09.808000+00:00"
}
```

---

## Remove a connection

<Endpoint method="DELETE" path="/api/v1/connections/:id" />

Removes a connection, as removing it on the **Apps** page does. This can't be undone. Requires the `connections:write` scope, and the same role permission as [connecting](#connect-an-app) it: **Run workflows** for a personal connection, **Manage apps** for a shared one. Otherwise the request gets `403` with the code `permission_denied`.

Removing a connection:

- turns off any workflow that listens for its trigger through it
- stops the steps that used it from working: they don't fall back to another connection to the same app

```bash
curl -X DELETE https://api-prod.lodol.com/api/v1/connections/66a2c4e6f8a0b2c4d6e8f0a1 \
  -H "Authorization: Bearer $LODOL_API_KEY"
```

**Response `200`:**

```json
{ "id": "66a2c4e6f8a0b2c4d6e8f0a1", "deleted": true, "restorable_until": null }
```

`restorable_until` is always `null`: a removed connection can't be restored. A connection that doesn't exist, has already been removed, or that the key's member can't use returns `404`.
