3

I know the request param in a firebase https.onRequest corresponds to a Express response.

I want to run the cloud function using this format (local testing):

http://localhost:5000/test-2c6e8/us-central1/coins?userid=1

So, now from the cloud function I just want to get the userId param. The test function I have written is:

exports.coins = functions.https.onRequest((request, response) => 
{
    var db = admin.firestore();
    response.json({query: JSON.stringify(request.query),
                   params: JSON.stringify(request.params),
                   body: JSON.stringify(request.body)});
    response.end();
});

and this is the output I get:

query   "{}"
params  "{\"0\":\"\"}"
body    "{}"

I have tried multiple things without any luck. Why is this happening?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Notbad
  • 5,936
  • 12
  • 54
  • 100
  • 1
    Your Cloud Function should run correctly if you deploy it. You may encounter problem depending on the way you test it, see https://stackoverflow.com/questions/56289923/call-firebase-cloud-function-via-get-and-return-parameters – Renaud Tarnec May 24 '19 at 12:35
  • If you find a problem with the local emulator, please file an issue on the project GitHub. https://github.com/firebase/firebase-tools – Doug Stevenson May 24 '19 at 17:14

1 Answers1

6

Short answer is req.query.name_of_the_parameter; for the long answer, you can read here.

Zorayr
  • 23,770
  • 8
  • 136
  • 129