8

I'm using Firebase as a simple game-server and have some settings that are relevant for both client and backend and would like to keep them in RemoteConfig for consistency, but not sure if I can access it from my cloud functions in a simple way (I don't consider going through the REST interface a "simple" way)

As far as I can tell there is no mention of it in the docs, so I guess it's not possible, but does anyone know for sure?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
N.J.
  • 679
  • 7
  • 13
  • Did you made a Function to access RemoteConfig using the REST interface you can share with us? – cmolina Apr 23 '18 at 21:44
  • No, sorry. I decided it wasn't worth the effort for a few variables so decided to just replicate them instead. – N.J. Apr 25 '18 at 06:16

2 Answers2

9

firebaser here

There is a public REST API that allows you to read and set Firebase Remote Config conditions. This API requires that you have full administrative access to the Firebase project, so must only be used on a trusted environment (such as your development machine, a server you control or Cloud Functions).

There is no public API to get Firebase Remote Config settings from a client environment at the moment. Sorry I don't have better news.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • The REST API that was introduced recently should be accessible from Cloud Functions, right? What would also be interesting: Do you need the Blaze plan to access that API? – creativecreatorormaybenot Aug 14 '18 at 22:54
  • Good point on the new REST API. I updated my answer. This REST API is available in projects on any plan. If you're having problems, post a question with the [minimal steps that reproduce where you are stuck](http://stackoverflow.com/help/mcve). – Frank van Puffelen Aug 15 '18 at 05:35
  • @FrankvanPuffelen This answer is over 4 years old, so I thought I'd just poke in case something has changed. – George Aug 16 '21 at 17:26
  • Not that I know of, but if it exists it'd be mentioned here: https://firebase.google.com/docs/remote-config – Frank van Puffelen Aug 16 '21 at 19:32
3

This is probably only included in newer versions of firebase (8th or 9th and above if I'm not mistaken).

// We first need to import remoteConfig function.
import { remoteConfig } from firebase-admin

// Then in your cloud function we use it to fetch our remote config values.
const remoteConfigTemplate = await remoteConfig().getTemplate().catch(e => {
 // Your error handling if fetching fails... 
}

// Next it is just matter of extracting the values, which is kinda convoluted, 
// let's say you want to extract `game_version` field from remote config:
const gameVersion = remoteConfigTemplate.parameters.game_version.defaultValue.value

So parameters are always followed by the name of the field that you defined in Firebase console's remote config, in this example game_version. It's a mouthful (or typeful) but that's how you get it.

Also note that if value is stored as JSON string, you will need to parse it before usage, commonly: JSON.parse(gameVersion).

Similar process is outlined in Firebase docs.

ado387
  • 162
  • 1
  • 9