> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vertracloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Stack Connection

> Connects an application of a stack to a database, a Blob folder or another application, injecting managed variables.

Connects an application of the stack to a database, a Blob folder or another application of the stack. The platform writes the variables into the application and, for a database, the client certificates into `/app/.vertra/certs/<database_id>/`. The network mode is `public`: the application reaches the public address of the database with a client certificate. Needs the `stacks:write` scope when called with an API key.

**stack\_id** `string` *required*

The stack ID.

**workspace\_id** `string`

The workspace the stack belongs to, when you act on it as the workspace owner.

**app\_id** `string` *required*

The application of the stack that receives the variables.

**database\_id** `string`

The database to connect to. Send exactly one of `database_id`, `blob_id` and `target_app_id`.

**blob\_id** `string`

The ID of the Blob member to connect to.

**target\_app\_id** `string`

Another application of the stack to connect to.

**env\_map** `object`

Variable names and what each receives. Without it the platform uses the standard names of the engine (`DATABASE_URL`, `MONGODB_URI`, `REDIS_URL`, `MYSQL_URL`), prefixed with the service name from the second connection of an engine. Allowed values:

* Database: `url`, `host`, `port`, `user`, `password`, `database`, `ssl.ca_path`, `ssl.cert_path`, `ssl.key_path`, `ssl.pem_path` (key, certificate and CA in one file, the format MongoDB reads), `ssl.p12_path` (PKCS#12 with an empty password, the format Prisma 6 and earlier read) and `prisma_url` (a PostgreSQL URL for Prisma 6 and earlier; never added by default).
* Another application (or the application itself): `url` and `domain` (the host name only, without the scheme). Both follow a change of subdomain or domain.
* Blob folder: `endpoint`, `bucket`, `region`, `prefix`, `access_key_id`, `secret_access_key` and `public_base_url` (empty when the folder is private).

### Response

`201` with the connection (same fields as [List Stack Connections](https://docs.vertracloud.app/api-reference/endpoint/stacks/bindings/list.md)) plus `restart_required` and `apps_to_restart`. An application reads variables and certificates only when it starts, so restart the applications listed in `apps_to_restart`.

```bash cURL theme={null}
curl -X POST https://api.vertracloud.app/v1/stacks/stk-abc123def456/bindings \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "app_id": "app-abc123def456",
    "database_id": "db-abc123def456",
    "env_map": { "DATABASE_URL": "url" }
  }'
```

### Errors

| Status | Code | When |
| - | - | - |
| 400 | `VALIDATION_ERROR` | Not exactly one target, or a value in `env_map` is not valid for the target. |
| 400 | `FORBIDDEN_KEY` | A variable name is reserved by the platform. |
| 409 | `ENV_DUPLICATE_KEY` | A variable name is already managed by another connection. |
| 403 | `WORKSPACE_OWNER_ONLY` | You are a workspace member, not the owner. |
| 404 | `STACK_NOT_FOUND` | The stack does not exist or belongs to another account. |
| 404 | `STACK_MEMBER_NOT_FOUND` | The application or the target is not a member of the stack. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.