Connect a Database to an Application

POST /v1/applications/{uuid}/database-connections

Connect one of the account's databases to an application, through one of the database's users. The app gets these variables in the chosen environment:

{PREFIX}DB_HOST / {PREFIX}DB_PORT plain
The database server's internal address and port.
{PREFIX}DB_NAME plain
The name inside MariaDB (db_name).
{PREFIX}DB_USER plain
The user's login (db_user).
{PREFIX}DB_PASSWORD secret
The user's current password.
{PREFIX}DATABASE_URL secret
mysql://<user>:<password>@<host>:<port>/<db_name>.

ngris builds the variables when it starts the app; the password is never stored among the app's environment variables. GET /v1/applications/{uuid}/env lists them with source: "database" (the password and URL masked). If the app is running, its current deploy is restarted so it picks them up (applied: true); otherwise it gets them on its next deploy. If the database or the user is still being created, the variables arrive once both are ready (env_pending: true) and ngris restarts the app again.

Only managed, full-stack and function apps can connect: they run on ngris, where the database is reachable. Nothing outside ngris can reach a database. A connection reserves its names on the app: it is refused when the app already has one of them (a variable you set, or another connection's) in an overlapping environment (all overlaps both), and while it exists PUT /v1/applications/{uuid}/env refuses those names.

Requires Databases write and Endpoints write, and a plan with managed databases.

Request body

database_uuid string (uuid)
Required. A database of the account, provisioning or ready.
user_uuid string (uuid)
Required. A user of that database (provisioning, ready or rotating).
env_prefix string
Optional. Empty (default) for DB_HOST … DATABASE_URL. Uppercased, with a trailing _ added when missing (orders → ORDERS_); it must then be a letter followed by up to 30 of A-Z, 0-9 and _, ending in _. Use a prefix to connect several databases to one app.
environment string
Optional. production, preview or all (default): the deploys that get the variables.

Response (201 Created)

connection object
The new connection, with its env_names.
applied bool
true when the app's running deploy was restarted to pick up the variables.
env_pending bool
true while the database or the user isn't ready: the variables reach the app once both are.

Errors

400
invalid request body; database_uuid and user_uuid are required; Prefix must be empty, or an uppercase letter followed by up to 30 of A-Z, 0-9 and _, ending in _ (e.g. ANALYTICS_); Environment must be production, preview or all; var set standard or wordpress; or This application type can't use a database: only managed, fullstack and function apps run where a database is reachable.
403
No Databases write or Endpoints write, no active account, Static application hosting is not available on your plan, or Managed databases are not available on your plan.
404
application not found, database not found or database user not found.
409
env_conflict: the app already uses some of the names; names lists them. Remove or rename them, or choose a prefix.
quota_paused: the app or the database is paused over your plan's limits.
database_status: the database is failed or deleting, or the user is failed or deleting (resource and status say which).
503
databases_unavailable.
Request
curl -X POST \ "https://api.ngris.com/v1/applications/019be838-d261-7d9b-9499-71995a3a91c6/database-connections" \ -H "X-API-KEY: <your_api_key>" \ -H "Content-Type: application/json" \ -d '{ "database_uuid": "019c2a41-7d3e-7b52-a1c4-5e9f0b3d6a18", "user_uuid": "019c2a41-7d40-7e15-9b63-2f8c4d1a7e95", "env_prefix": "orders", "environment": "all" }'
Response — 201 Created
{ "connection": { "uuid": "019c2a71-9a2d-7d06-8e41-3f7b2c9d0a58", "env_prefix": "ORDERS_", "environment": "all", "var_set": "standard", "created_at": "2026-10-18T09:02:00Z", "application_uuid": "019be838-d261-7d9b-9499-71995a3a91c6", "application_name": "orders-api", "database_uuid": "019c2a41-7d3e-7b52-a1c4-5e9f0b3d6a18", "database_name": "orders-db", "database_user_uuid": "019c2a41-7d40-7e15-9b63-2f8c4d1a7e95", "database_user_name": "app", "env_names": ["ORDERS_DB_HOST", "ORDERS_DB_PORT", "ORDERS_DB_NAME", "ORDERS_DB_USER", "ORDERS_DB_PASSWORD", "ORDERS_DATABASE_URL"] }, "applied": true, "env_pending": false }
Response — 409 (names in use)
{ "error": "These environment variable names are already used by the application: DATABASE_URL, DB_HOST. Remove or rename them, or choose a prefix.", "code": "env_conflict", "names": ["DATABASE_URL", "DB_HOST"] }

Disconnect a Database from an Application

DELETE /v1/applications/{uuid}/database-connections/{connection_uuid}

Remove a connection: the app loses its variables, and its running deploy is restarted so the change takes effect (applied). The database and the user stay. Works while the app or the database is paused, and on a downgraded plan. Requires Databases delete and Endpoints write.

Response (200 OK)

{"status": "disconnected", "applied": true}. applied is false when no running deploy was restarted (the app isn't running, it is paused, or a rollout is already under way); the change then applies on its next deploy or restart.

Errors

403
No Databases delete or Endpoints write, no active account, or Static application hosting is not available on your plan.
404
application not found or database connection not found (the connection isn't this app's).
409
database_bundled: A WordPress site's own database can't be disconnected from it.
503
databases_unavailable.
Request
curl -X DELETE \ "https://api.ngris.com/v1/applications/019be838-d261-7d9b-9499-71995a3a91c6/database-connections/019c2a71-9a2d-7d06-8e41-3f7b2c9d0a58" \ -H "X-API-KEY: <your_api_key>"
Response — 200 OK
{ "status": "disconnected", "applied": true }