# POST /v1/connections

> Get a connect link for one app, for one user (user_id) or the company's own Bash.

In [Connected apps API](https://vestra.ai/developers/reference/api/connected-apps.md): The apps each user connects through a sign-in link, and the apps they may choose from.

Send `Authorization: Bearer vk_test_...` on every call.

Get a connect link for one app, for one user (user_id) or the company's own Bash. After consent the user lands on your return_url (or your first allowed one, or our own page), and a webhook fires. The link carries the id of the connection it makes.

Your API key, scope `runtime` or `all`. On the card: [`connect`](https://vestra.ai/developers/connect.md). Every call here is a checked sample.

## Request

Headers:

- `Idempotency-Key` (`string`): Send the same key to retry this call safely for 24 hours.

Body:

- `user_id` (`string`): Whose Bash: your id for the user. Absent: your company's own Bash. Example: `traveller-42`.
- `app` (`string`, required): The app to connect, by its slug from GET /v1/apps. Example: `gmail`.
- `return_url` (`string (URL)`): Where the user lands after they sign in; it must match one of your allowed return URLs. Absent: your first allowed return URL, or our own page. Limits: at most 2048 characters. Example: `https://app.example.com/connected`.
- `deployment_id` (`string`): The deployment whose `apps` decide whether this app is allowed, by its `dep_` id or name. Absent: the company default's. Limits: 1 to 128 characters.

## Answers 200 or 201

- `object` (`"connect_link"`): Always `connect_link`.
- `id` (`string | null`): The connection this link makes (`con_`), to read with GET /v1/connections/{connection_id}; null only when there is none to make (an app with no sign-in).
- `status` (`"pending" | "connected"`): `pending`: send the user to `url`. `connected`: they already had this app, or it needs no sign-in.
- `url` (`string | null`): The sign-in link: send it to your user, or open it yourself for your company's own Bash. Null when there is nothing to sign in to.
- `connection` (`object | null`): The connection when it is already made; null while it is pending.
  - `object` (`"connection"`): Always `connection`.
  - `id` (`string`): The connection's id. Example: `con_8f2k`.
  - `user_id` (`string | null`): Your id for the user; null for your company's own Bash.
  - `app` (`string`): The app, by its slug. Example: `gmail`.
  - `status` (`"active" | "pending" | "initializing" | "expired" | "revoked" | "inactive" | "failed"`): `active`: Bash can use it. `pending` or `initializing`: the sign-in is not finished. `expired`, `revoked`, `inactive` or `failed`: it no longer works, and the user connects it again.
  - `label` (`string | null`): The account's label, usually its email; null when the app gives none.
  - `created_at` (`string`): When it was connected, as an ISO 8601 date and time in UTC.
- `expires_at` (`string`): When the link stops working, as an ISO 8601 date and time in UTC.

## Code

**TypeScript**

```ts
const link = await vestra.user('traveller-42').connect('gmail');
```

**Python**

```python
link = vestra.user("traveller-42").connect("gmail")
```

**CLI**

```bash
vestra connect gmail --user traveller-42
```

**HTTP**

```bash
# Get a sign-in link for one app. It is for one user: send them its url.
curl "$VESTRA_BASE_URL/v1/connections" \
  -H "Authorization: Bearer $VESTRA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "user_id": "traveller-42", "app": "gmail" }'

# List their apps. You can also list the catalog your users may pick from.
curl "$VESTRA_BASE_URL/v1/connections?user_id=traveller-42" \
  -H "Authorization: Bearer $VESTRA_API_KEY"

curl "$VESTRA_BASE_URL/v1/apps?search=calendar" \
  -H "Authorization: Bearer $VESTRA_API_KEY"

# Disconnect an app. user_id says whose connection it is.
curl -X DELETE "$VESTRA_BASE_URL/v1/connections/con_7hs?user_id=traveller-42" \
  -H "Authorization: Bearer $VESTRA_API_KEY"
```

**MCP**

```json
{
  "method": "tools/call",
  "params": {
    "name": "connect",
    "arguments": { "user": "traveller-42", "app": "gmail" }
  }
}
```
