---
title: "Link a database to an app"
method: POST
path: "/api/v1/apps/services/{service_id}/bindings"
tags: ["Raff Apps"]
---

# Link a database to an app

`POST /api/v1/apps/services/{service_id}/bindings`

## Request

- Base URL: `https://api.rafftechnologies.com`
- URL: `https://api.rafftechnologies.com/api/v1/apps/services/{service_id}/bindings`
- Auth: API key in header `X-API-Key`

Link a running managed database to an app. Raff creates a database user
for this app, sets `{PREFIX}_URL`, `_HOST`, `_PORT`, `_USER`,
`_PASSWORD`, `_NAME` and `_CA_CERT` (prefix `DATABASE` by default; the
first link also fills a template's own settings) and redeploys the app.
Connections go over Raff's private network and always use TLS; check
the server with `{PREFIX}_CA_CERT`.

<Note>
Before linking, you need the **database ID**: get it from
[List Databases](/api-reference/databases/list-databases).
</Note>

## Path parameters

- `service_id` string, required

## Request body

- CreateAppBindingRequest
  - `binding_type` 'database', required
  - `resource_id` string, uuid, required: A running managed database of this account
  - `env_prefix` string: Prefix for the variables, uppercase letters, digits and underscores (default `DATABASE`). Give a second database its own prefix.

## Response `200`

Linked; the app redeploys with the new settings

- object
  - `success` boolean
  - `binding` AppBinding: A managed database linked to an app.
    - `id` string, uuid
    - `service_id` string, uuid
    - `binding_type` 'database'
    - `resource_id` string, uuid: The database's ID
    - `resource_name` string
    - `env_prefix` string: Prefix of the variables this link sets (`DATABASE` by default)
    - `injected_keys` string[], nullable
    - `status` 'provisioning' | 'active' | 'rotating' | 'error' | 'deleting'
    - `status_message` string
    - `created_at` string, date-time

## Other responses

- `400`: Invalid request parameters
- `401`: Authentication required
- `404`: Resource not found
- `409`: Conflicts with what exists, for example a name already in use

## Changes

- **2026-10-19** `e80a4b1b5024`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/rafftechnologies/apis/raff-api/changes/api/v1/apps/services/:service_id/bindings/post.md)

---

[API](https://skmtc.dev/rafftechnologies/apis/raff-api.md) - [All operations](https://skmtc.dev/rafftechnologies/apis/raff-api/llms.txt) - [OpenAPI document](https://skmtc.dev/rafftechnologies/apis/raff-api/revisions/3d30cde0acb4?raw)
