There is no public API to do this.
However, it can be done...
First, you'll need the unique name of your database. You can look that up by it's attachment name/alias, which is usually DATABASE
or HEROKU_POSTGRES_[COLOR]
by default, or anything custom you might have assigned with heroku addons:{create,attach} --as NAME
. Using an alias of DATABASE
by default, here's how you might get it using curl
and jq
:
$ curl -H "Authorization: Bearer $API_KEY" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/$APP_NAME/addon-attachments/DATABASE \
| jq .addon.name
"postgresql-colorful-12345"
Then, assuming that name is saved stored in $DBNAME
, you can rotate its credentials like so:
$ curl -X POST -u "x:$API_KEY" \
https://$DOMAIN/client/v11/databases/$DBNAME/credentials_rotation
{"status":"ok","url":"[REDACTED]","message":"Password reset."}
$DOMAIN
will be postgres-api.heroku.com
for paid plans and postgres-starter-api.heroku.com
for free/hobby plans, IIRC.
This API could change at any time though as it is considered a private API, so factor that into your decision to use it.