Connection
Get the connection string of a database or of one environment's branch.
GET
/databases/{databaseId}/connectionThe connection string and its parts. Without
environmentId: the primary (production) branch.Prop
Type
curl "https://api.helipod.io/api/databases/$DB/connection?environmentId=$STAGING" \
-H "Authorization: Bearer hel_your_key"{
"success": true,
"data": {
"environmentId": "7c2f9e10-1d4b-4a8e-b6a1-0e9d3c5f2a71",
"uri": "postgresql://helipod_db_owner:••••••@db-pool.example.net/helipod_db?sslmode=require",
"host": "db-pool.example.net",
"port": 5432,
"database": "helipod_db",
"user": "helipod_db_owner",
"password": "••••••",
"sslmode": "require",
"pooled": true
}
}uriis ready for any Postgres driver or ORM (pg, Prisma, Drizzle, SQLAlchemy,psql, ...). The other fields are the same values for drivers that want them separately.- The connection goes through a pooler, so many short-lived connections (serverless functions, many replicas) are fine. SSL is required.
- An environment without its own branch answers
409 ENVIRONMENT_BRANCH_MISSING. Create one with Branches, or omitenvironmentIdto use production.
This response contains the password
Store uri as a secret variable (for example DATABASE_URL) on the service that needs it. Don't put it in code, logs or chat. Secret variables are never returned by the API once set, see Variables.
Use it in a service
URI=$(curl -s https://api.helipod.io/api/databases/$DB/connection \
-H "Authorization: Bearer hel_your_key" | jq -r .data.uri)
curl -X PUT https://api.helipod.io/api/containers/services/$SERVICE/variables \
-H "Authorization: Bearer hel_your_key" -H "Content-Type: application/json" \
-d "{ \"variables\": { \"DATABASE_URL\": \"$URI\" }, \"secrets\": [\"DATABASE_URL\"] }"Then redeploy the service. For staging, read the connection with the staging environmentId and set it on the staging service, so staging never writes to production data.
From your laptop
psql "$(curl -s https://api.helipod.io/api/databases/$DB/connection -H "Authorization: Bearer hel_your_key" | jq -r .data.uri)"An idle database (scaled to zero) wakes up on the first connection, which takes about a second.