Firebase: How to programmatically obtain the default realtime database URL for a project?

Viewed 159

We have 3 Firebase projects – one for production, one for staging and one for development.

Production and staging were created before Dec 2020 and their "project names" and database ids match: ("project-foo" maps to "project-foo.firebaseio.com" database url).

For a newly created "development" project, after I pressed "Create Database" in the dashboard, new database got a url that doesn't match the project name: ("project-foo-development" maps to "project-foo-development-default-rtdb.europe-west1.firebasedatabase.app").

I am writing a script that operates on all 3 environments and it’s clear that I can’t make an assumption that database url will match the project id, or that the top level domain for database hosting will be the same.

How do I obtain the default database URL dynamically from firebase so I can apply my scripting to all 3 environments?

I understand that I can obtain the url from the dashboard, but ideally I’d only need the project names, since these ids/urls seem to be controlled by Firebase.

1 Answers

I quickly tested this with the REST API, and I can get the correct value from its projects.getAdminSdkConfig call. In the result of that call you'll find a databaseURL key with the full database URL as its value.

Related