The Firebase Remote Config Java quickstart app demonstrates retrieving and updating the Firebase Remote Config template.
This is a simple example of using the Firebase Remote Config REST API to update the Remote Config template being used by clients apps.
- Add Firebase to your Android Project.
- Create a service account as described in Adding Firebase to your Server and download the JSON file.
- Copy the private key JSON file to this folder and rename it to
service-account.json.
- Change the
PROJECT_IDvariable inConfigure.javato your project ID.
-
From the
configdirectory run./gradlew run -Paction=getto retrieve the template.- The returned template is stored in a file named
config.json. - Note the Etag printed to the console you will need to use it when publishing template updates.
- The returned template is stored in a file named
-
Update the template.
-
If your template already has parameters, adjust one or more of the values.
-
If your template is empty, update it to look like this:
{ "conditions": [ { "name": "AndroidUsers", "expression": "device.os == 'android'", "tagColor": "PURPLE" }, { "name": "iOSUsers", "expression": "device.os == 'ios'", "tagColor": "GREEN" } ], "parameters": { "welcome_message": { "defaultValue": { "value": "Welcome" }, "conditionalValues": { "AndroidUsers": { "value": "Welcome Android User" }, "iOSUsers": { "value": "Welcome iOS User" } } } } }
-
-
From the
configdirectory run./gradlew run -Paction=publish -Petag='<LATEST_ETAG>'to update the template.- Be sure to set the etag to the one that was last printed in the console.
-
Confirm in the console that the template has been updated.
- At this point mobile clients can fetch the updated values.
This section provides some additional information about how the Remote Config REST API should be used when retrieving and updating templates.
Each time the Remote Config template it retrieved an Etag is included. This Etag is a unique identifier of the current template on the server. When submitting updates to the template you must include the latest Etag to ensure that your updates are consistent.
In the event that you want to completely overwrite the server's template use an Etag of "*". Use this with caution since this operation cannot be undone.