Firebase: Introducing the project management API

Hiranya Jayathilaka
Dec 3, 2018 · 3 min read

Firebase is rolling out a new API in the Admin SDK for setting up and managing Firebase projects. So far this API has landed in the Node.js and Java flavors of the Admin SDK, with more launches expected in the future. Developers can use this API to create apps in a Firebase project, list the existing apps, and update the metadata associated with them. This means developers can now implement backend services, serverless functions and other administrative tools to automate a number of management tasks related to Firebase projects.

To use the new API, you must first import and initialize the Firebase Admin SDK. Then you can create apps using it as shown in listing 1.

Listing 1: Create a new app in a project

Note that no arguments are passed to the initializeApp() method. This implies the Admin SDK in this example is using Application Default Credentials (ADC). When executed in a managed environment such as Google Cloud Functions, listing 1 creates a new Android app in the same Firebase project as the one used to deploy the code. To execute this example locally, you can set the GOOGLE_APPLICATION_CREDENTIALS environment variable, and point it to a service account JSON file. In that case the new app is created in the same Firebase project as the service account.

The Admin SDK uses the following 3-stepped protocol to determine the target Firebase project for project management operations:

  1. Check if the projectId app option has been specified when initializing the SDK.
  2. Check if a project can be discerned from the credentials used to initialize the SDK. This is possible when the SDK is initialized with service account credentials or ADC.
  3. Check if the GOOGLE_CLOUD_PROJECT environment variable is set.

If you choose to specify the project ID as an app option (step 1) or as an environment variable (step 3), you should also specify valid credentials that have authorization over the target project. Obviously you cannot make changes to a project that you have no authorization over. If the SDK fails to determine a project ID by following the above steps, the projectManagement() API throws an error indicating the problem.

Having created some apps, now lets try to query them using the Admin SDK. Listing 2 illustrates how this is accomplished.

Listing 2: Query all Android apps in a project

The call to listAndroidApps() returns an array of objects that can be used to further inspect and update individual apps. Alternatively, if the ID of a specific app is already known, you can bypass calling listAndroidApps(), as shown in listing 3.

Listing 3: Query a specific app directly using its ID

In addition to querying app metadata, you can also perform certain update tasks such as adding SHA certificates to Android apps, and changing the display names of apps. The above examples only demonstrate the Android-related methods in the new API, but it has methods for managing IOS apps too. You can check out the full API surface in the documentation.

This Firebase project management API is still a work in progress. More language support, and more features can be expected in the future. In the meantime try out what’s released so far, and engage with the Firebase community with feedback, suggestions, and code contributions. If you have any success stories of how this feature has helped you, I’d love to hear them. If you run into any issues or limitations, I’d like to know about those experiences too. Happy coding with Firebase!

Hiranya Jayathilaka

Written by

Software engineer at Google. Enjoys working at the intersection of cloud, mobile and programming languages. Fan of all things tech and open source.