Connect a Database to an Application
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:
db_name).db_user).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
provisioning or ready.provisioning, ready or rotating).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.production, preview or all (default): the deploys that get the variables.Response (201 Created)
env_names.true when the app's running deploy was restarted to pick up the variables.true while the database or the user isn't ready: the variables reach the app once both are.Errors
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.Static application hosting is not available on your plan, or Managed databases are not available on your plan.application not found, database not found or database user not found.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).
databases_unavailable.Disconnect a Database from an Application
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
Static application hosting is not available on your plan.application not found or database connection not found (the connection isn't this app's).database_bundled: A WordPress site's own database can't be disconnected from it.databases_unavailable.