I know that when I create a branch with a connection, I’ll get the connection_uris in the response object. Is it possible to get the connection_uris from an existing branch? I did not find it in the swagger docs unfortunately. If not, then this would be a feature request
Hi @ThibaultJanBeyer ,
To ensure I understand your use case correctly, do you need the API to return a connection_uri from a branch id? What other parameter are you using?
You can get the PGHOST of a branch using the https://console.neon.tech/api/v2/projects/<PROJECT_ID>/branches/<BRANCH_ID>/endpoints
endpoint.
curl --request GET \
--url https://console.neon.tech/api/v2/projects/<PROJECT_ID>/branches/<BRANCH_ID>/endpoints \
--header 'accept: application/json' \
--header 'authorization: Bearer API_KEY'
You will get the following result:
{
"endpoints": [
{
"host": "ep-gentle-night-193152.us-east-2.aws.neon.tech",
"id": "ep-gentle-night-193152",
"project_id": "morning-meadow-820265",
"branch_id": "br-cool-silence-987406",
...
}
]
}
See the API reference for more detail.
You can then construct your branch connection string like so: postgres://PGUSER:PGPASSWORD@PGHOST/PGDATABASE
However, dynamically reconstructing your connection string is not recommended as it is prone to error.
Please let me know if this helps.
Hi, yes I wanted to create a CLI for local development that prompts the user to either select an existing NEON branch or create a new one if none exist yet to work with locally. Creating a new one returns the connection_uri which I can just use to inject into the .env
file kinda like you did in the script on branch creation however, for using an existing one I would have to create it dynamically like you answered which is not ideal
Thanks for clarifying and for your feedback. I’ll share this with the team.