Update connection
Replace the config of a connection. config has one member, named after the type of the resource of the connection.
The request replaces the whole config, so send every part you want to keep. connections.listConnections gives the config the connection has now. If the connection is gone, you get a 404, and the request creates nothing.
Deployments that run do not change. Start a new deployment to give the environment the new config.
planetscale_database
config.planetscaleDatabase.branch takes the branch id or its name, such as main. A connection stays on its branch. Another branch gets a 412. Delete the connection and create it again to move the environment to another branch. envVars names the variable of each URL:
urlis the read-write URL, and is required.unpooledUrlis the read-write URL that skips PgBouncer. Only Postgres databases have it.replicaUrlturns the read-only replica URL on. Send the config without it to turn it off.
Unkey sets names that start with UNKEY, and app connections set names that end with _HOST, so a variable cannot use either.
- A read-only replica URL needs a branch with replicas. Without them you get a
412. - If PlanetScale deleted the branch, the request can still turn the read-only replica URL off. Send
branchas the id the connection has. Any other change gets a404. - A variable name that the environment already has gets a
400that names it.
The workspace must have the databases, connections and app_v2 flags. Without them you get a 403.
Required Permissions
Your root key must be able to read the resource. For a planetscale_database, that is one of these permissions:
unkey:v1:<workspace_id>:projects/*/databases/*#read(to read the databases of any project)unkey:v1:<workspace_id>:projects/<project_id>/databases/*#read(to read the databases of one project)unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>#read(to read one database)
It must also be able to write the credentials of the database, because Unkey creates a credential for each deployment of the connected environment. The caller never gets the credential. That is one of these permissions:
unkey:v1:<workspace_id>:projects/*/databases/*/credentials/*#write(for the databases of any project)unkey:v1:<workspace_id>:projects/<project_id>/databases/*/credentials/*#write(for the databases of one project)unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>/credentials/*#write(for one database)
And it must be able to write the connection, with one of these permissions:
unkey:v1:<workspace_id>:projects/*/apps/*/environments/*/connections/*#write(to change any connection)unkey:v1:<workspace_id>:projects/<project_id>/apps/<app_id>/environments/<environment_id>/connections/*#write(to change the connections of one environment)unkey:v1:<workspace_id>:projects/<project_id>/apps/<app_id>/environments/<environment_id>/connections/<connection_id>#write(to change one connection)
Replace <workspace_id> with the authenticated workspace ID.
Authorizations
Unkey uses bearer tokens for authentication. Public integrations use root keys, while the dashboard proxy uses short-lived JWTs. To authenticate, include the token in the Authorization header of each request:
Root keys have specific permissions attached to them, controlling what operations they can perform. Resource permissions use Unkey Resource Names plus actions, like unkey:v1:ws_123:projects/*/keyspaces/*/keys/*#write.
Security best practices:
- Keep root keys secure and never expose them in client-side code
- Use different root keys for different environments
- Rotate keys periodically, especially after team member departures
- Create keys with minimal necessary permissions following least privilege principle
- Monitor key usage with audit logs.
Body
Response
The connection has the config of the request.