Connect a service to a database on its cluster. Postgres adds DATABASE_URL (through the pooler when it's on) and DATABASE_URL_DIRECT, plus DATABASE_URL_READ with read replicas. MySQL adds DATABASE_URL (mysql://, to the primary), MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD and MYSQL_DATABASE. KV adds REDIS_URL (which follows failover and sends reads to read replicas), plus KV_REST_API_URL, KV_REST_API_TOKEN and KV_REST_API_READ_ONLY_TOKEN (reads only) with its REST API. With env, it adds only those, under the service's own names. With prefix, it adds all of them with that prefix, so two databases' variables don't clash. They're secret variables and apply on the service's next deploy.
API key access: full.
apiKeyAuthorizationBearer <pyo_…>An API key from the dashboard's API keys page: Authorization: Bearer pyo_…. Keys can expire, and an expired one gets a 401.
application/jsonConnect a service to a database on its cluster. Postgres adds DATABASE_URL (through the pooler when it's on) and DATABASE_URL_DIRECT, plus DATABASE_URL_READ with read replicas. MySQL adds DATABASE_URL (mysql://, to the primary), MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASSWORD and MYSQL_DATABASE. KV adds REDIS_URL (which follows failover and sends reads to read replicas), plus KV_REST_API_URL, KV_REST_API_TOKEN and KV_REST_API_READ_ONLY_TOKEN (reads only) with its REST API. With env, it adds only those, under the service's own names. With prefix, it adds all of them with that prefix, so two databases' variables don't clash. They're secret variables and apply on the service's next deploy.
API key access: full.
op*"connectDatabase""connectDatabase"id*stringserviceId*stringenv?|The service's own names for them: {"WORDPRESS_DB_HOST": "MYSQL_HOST", …}, each a variable the database offers, or several joined by ":" (MYSQL_HOST:MYSQL_PORT). Under its own names, Postgres also offers POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DATABASE (the primary, not the pooler), and KV REDIS_HOST, REDIS_PORT and REDIS_PASSWORD. Kept, so they follow its changes.
prefix?|Instead of env: all its variables, each named with this prefix (MYSQL gives MYSQL_DATABASE_URL…), so a service can use databases whose variables would clash.
Done. Always ok: true, and some operations add more, such as a new API key or a join command. A warning comes with a change that went through but won't fully take effect yet, such as more replicas than the servers have room for.
application/jsoncurl -X POST 'https://your-pyo.example.com/api/v1/ops' \
-H 'Content-Type: application/json' \
-d '{
"id": "mdb_8kq2x7ad",
"op": "connectDatabase",
"serviceId": "svc_8kq2x7ad"
}'{}