Databases through the API

Use these routes to operate an existing database project (PostgreSQL, MariaDB, or ClickHouse). To create the database, see Create, list, and delete projects. Valkey services (Key-Value, Cache, and Queue) use the Managed services routes.

Authentication and permissions

All routes accept an organization API Key (x-api-key: znf_... or Authorization: Bearer znf_...) or a user token with x-organization-id. Permissions use the database:<project-id> resource:

RouteScope
GET /v1/project/:id/database/statusdatabase.status.read
GET /v1/project/:id/database/connectiondatabase.connection.read
GET /v1/project/:id/database/linked-applicationsdatabase.password.rotate
PATCH /v1/project/:id/database/passworddatabase.password.rotate
PATCH /v1/project/:id/database/versiondatabase.version.update
PATCH /v1/project/:id/database/exposuredatabase.exposure.update
PATCH /v1/project/:id/database/tlsdatabase.exposure.update

owner has full access. assistant, member, and API Keys need the scope on the database ID or on database:*. Without it, the response is 403 with insufficient organization permission.

Read the state

GET /v1/project/:id/database/status
{
  "status": "success",
  "message": "got database status successfully",
  "data": {
    "project_id": "6650f1a2b3c4d5e6f7a8b9c1",
    "name": "orders-db",
    "plan": "db-basic",
    "status": "running",
    "exposure": "public"
  }
}

status uses the same states as the project: running when the database accepts connections, creating while it is still starting, failing when it stopped accepting connections or did not become available within 15 minutes of creation, and stopped when it is stopped. During other operations it returns the project status (for example resuming or deleting). The engine object (postgres, mariadb or clickhouse) repeats the same status. For the project lifecycle and the failure reason, use GET /v1/project/:id (Project information).

On Analytics databases (ClickHouse), data.clickhouse carries only status, instances, readyInstances, and storage_gb (plus vcpu and memory_mb when available), always in GB, vCPU, and MB:

{
  "status": "success",
  "message": "got database status successfully",
  "data": {
    "project_id": "6650f1a2b3c4d5e6f7a8b9c2",
    "name": "analytics-orders",
    "plan": "analytics-production",
    "status": "running",
    "exposure": "public",
    "clickhouse": {
      "status": "running",
      "instances": 3,
      "readyInstances": 3,
      "storage_gb": <capacity in GB>
    }
  }
}

exposure shows whether public access is on (public) or off (private) and appears for every engine. Do not rely on other fields. During a plan change, instances and readyInstances help track progress; for the state of the change, use plan_change in GET /v1/project/:id (Project information).

A stopped database returns status: "stopped" for every engine. If the project does not exist in the organization or is not a database, the response is 404 with database project not found; an :id in an invalid format returns 400.

Limit: 50 requests per minute.

Read the connection

GET /v1/project/:id/database/connection
{
  "status": "success",
  "message": "got database connection successfully",
  "data": {
    "host": "<host>",
    "port": 5432,
    "database": "<database>",
    "username": "<username>",
    "connectionStringRO": "postgresql://<username>:********@<read-host>:5432/<database>?sslmode=require",
    "connectionString": "postgresql://<username>:********@<host>:5432/<database>?sslmode=require",
    "exposure": "public",
    "tls": { "required": true }
  }
}

This route never returns the password: connection strings come with the password masked as ********. connectionStringRO only appears when the database has a read-only endpoint (for example, PostgreSQL with 2 or more instances). ClickHouse databases also return httpsPort. exposure shows whether the public host and port accept connections (public) or the database is reachable only through private connections (private); the connection details stay the same in both states. tls.required shows whether the database requires TLS on connections; on MariaDB, it is always true (see Require TLS or not). If you lost the password, renew it with the route below. A project that does not exist or is not a database returns 404 with database project not found.

Limit: 50 requests per minute.

List linked applications

GET /v1/project/:id/database/linked-applications

Lists the applications that use this database and the names of the environment variables that received the connection: those created together with the database from a template and those linked by an internal connection. The via field shows where the link comes from (template, connection, or both). Deleted applications are not listed. Check it before renewing the password to know which applications will need new credentials. Only applications the credential can read (project.read) are listed. A project that does not exist returns 404; a project that is not a database returns 400.

{
  "status": "success",
  "data": {
    "linked_applications": [
      { "project_id": "6650f1a2b3c4d5e6f7a8b9c0", "variable_names": ["DATABASE_URL"], "via": ["template"] }
    ]
  }
}

Avoid repeated calls: the password renewal response also includes this list.

Limit: 50 requests per minute.

Renew the password

PATCH /v1/project/:id/database/password

Generates a new random password for the PostgreSQL, MariaDB, or ClickHouse database. Send an empty body ({}). The operation is synchronous: the 200 response only arrives after the new password is applied, and the previous password stops working. Update the applications that use the database. For Key Value, cache, and queue, use the managed service credential rotation.

{
  "status": "success",
  "message": "database credentials updated with success",
  "data": {
    "password": "<new-password>",
    "linked_applications": [
      { "project_id": "6650f1a2b3c4d5e6f7a8b9c0", "variable_names": ["DATABASE_URL"], "via": ["template"] }
    ]
  }
}

The new password only appears in this response, sent with Cache-Control: no-store. Store it securely before discarding the response.

The database must be running. If the renewal fails midway, Zenifra restores the previous credential. While a renewal is open, stopping the database, changing the plan, or changing instances or storage returns 409 with PROJECT_OPERATION_IN_PROGRESS.

CodeSituation
404Project not found
409DATABASE_CREDENTIAL_ROTATION_IN_PROGRESS: a renewal is already in progress or being recovered
409PROJECT_OPERATION_IN_PROGRESS: another operation is in progress for the project
409PROJECT_STATE_CONFLICT: the database is not running
422PROJECT_OPERATION_NOT_SUPPORTED: the project is not PostgreSQL, MariaDB, or ClickHouse
503DATABASE_CREDENTIAL_ROTATION_FAILED: the renewal could not be completed; try again

Limit: 5 requests per minute.

Update the version

PATCH /v1/project/:id/database/version
FieldTypeRequiredDescription
versionstringYesTarget major version, among those offered by the database plan: PostgreSQL 16, 17, or 18; MariaDB 11. Check each plan's versions in GET /v1/project/database/catalog
{
  "version": "18"
}
{
  "status": "success",
  "message": "database version updated with success"
}

The change only moves forward: you cannot go back to an earlier version. The database must be running. Back up and validate application compatibility before changing versions. ClickHouse has a single available version and does not accept this operation.

CodeSituation
400Missing version or DATABASE_VERSION_NOT_AVAILABLE: the version is not offered by the database plan
404Project not found
409DATABASE_VERSION_ALREADY_CURRENT: the database is already on the requested version
409DATABASE_VERSION_DOWNGRADE_NOT_SUPPORTED: the requested version is earlier than the current one (Database versions cannot be downgraded)
409PROJECT_STATE_CONFLICT: the database is not running; or PROJECT_OPERATION_IN_PROGRESS: another operation is in progress
422PROJECT_OPERATION_NOT_SUPPORTED: the project is not PostgreSQL or MariaDB (ClickHouse, Key Value, HTTP applications, Jobs, and previews)
500Failure applying the new version

Limit: 5 requests per minute.

Turn public access on or off

PATCH /v1/project/:id/database/exposure

Turns public access on or off for a PostgreSQL, MariaDB, or ClickHouse database. For Valkey, use PATCH /v1/managed-services/:id/exposure.

FieldTypeRequiredDescription
exposurestringYespublic to accept TLS connections on the public host and port; private so the public address stops accepting connections
{
  "exposure": "private"
}
{
  "status": "success",
  "message": "public access updated with success",
  "exposure": "private"
}

With private, the database is reachable only through private connections between applications or from inside the platform. With public, it accepts connections again on the same host and the same port, and the external connection string stays the same. Private connections and password renewal work in both states. The current state appears in the exposure field of GET /v1/project/:id, GET /v1/project/:id/database/connection, and GET /v1/project/:id/database/status, and the GET /v1/project/database/catalog catalog returns exposure_modes: ["public", "private"] for each engine.

The database must be running. If the change cannot be completed, Zenifra keeps the previous state.

CodeSituation
400exposure missing or different from public and private, or invalid :id
403Missing the database.exposure.update permission on the database (insufficient organization permission)
404Project not found in the organization, or not PostgreSQL, MariaDB, or ClickHouse (project not found)
409PROJECT_STATE_CONFLICT: the database is not running
409PROJECT_OPERATION_IN_PROGRESS: another operation is in progress on the project
422PROJECT_OPERATION_NOT_SUPPORTED: the project does not support this operation
429Rate limit exceeded
503DATABASE_EXPOSURE_UPDATE_FAILED: public access could not be updated and the previous state was kept; try again

Limit: 5 requests every 5 minutes.

Require TLS or not

PATCH /v1/project/:id/database/tls

Sets whether a PostgreSQL database requires TLS on connections. By default, it does. MariaDB always requires TLS and does not accept this operation.

FieldTypeRequiredDescription
requiredbooleanYestrue to accept only TLS connections; false to also accept unencrypted connections
{
  "required": false
}
{
  "status": "success",
  "tls": { "required": false }
}

With false, the connection strings still use TLS (sslmode=require), and the database also accepts clients without TLS. With true, connections without TLS are rejected with an error that contains no encryption. Requesting the current state returns 200 with no change. The state appears in tls.required of GET /v1/project/:id/database/connection.

The database must be running. If the change cannot be completed, Zenifra keeps the previous state.

CodeSituation
400required missing or not a boolean, or invalid :id
403Missing the database.exposure.update permission on the database (insufficient organization permission)
404Project not found in the organization, or not PostgreSQL or MariaDB (project not found)
409PROJECT_STATE_CONFLICT: the database is not running
409PROJECT_OPERATION_IN_PROGRESS: another operation is in progress on the project
422PROJECT_OPERATION_NOT_SUPPORTED: the database is MariaDB, which always requires TLS
429Rate limit exceeded
503DATABASE_TLS_UPDATE_FAILED: TLS could not be changed and the previous state was kept; try again

Limit: 5 requests every 5 minutes.

Examples

curl "https://api.zenifra.com/v1/project/6650f1a2b3c4d5e6f7a8b9c1/database/connection" \
  -H "x-api-key: znf_..."

curl -X PATCH "https://api.zenifra.com/v1/project/6650f1a2b3c4d5e6f7a8b9c1/database/password" \
  -H "x-api-key: znf_..." \
  -H "Content-Type: application/json" \
  -d '{}'

curl -X PATCH "https://api.zenifra.com/v1/project/6650f1a2b3c4d5e6f7a8b9c1/database/exposure" \
  -H "x-api-key: znf_..." \
  -H "Content-Type: application/json" \
  -d '{"exposure":"private"}'

curl -X PATCH "https://api.zenifra.com/v1/project/6650f1a2b3c4d5e6f7a8b9c1/database/tls" \
  -H "x-api-key: znf_..." \
  -H "Content-Type: application/json" \
  -d '{"required":true}'

Next steps

Last updated on

On this page