Home > Software engineering >  Read JSON body Firebase Cloud Functions
Read JSON body Firebase Cloud Functions

Time:11-13

I have a simple cloud function like so:

exports.sendReactionNotification = functions.https.onRequest(async (req, res) => {
  console.log("received reaction");
  functions.logger.log(req.body);
  console.log(req.body["jsonPayload"]);
  return;
});

But the above logs "undefined" in the google cloud console. I have also tried dot notation like so: req.body.jsonPayload. But I get this error instead: TypeError: Cannot read properties of undefined (reading 'reaction')

The webhook I am receiving the api call from sends a reaction, so that is where the "reaction" in the above error message comes from. I am tearing at my hair because this is mean to be simple, but I can't tell what the issue is.

This is what the JSON object looks like (the result of the functions.logger.log(req.body) above: JSON object

CodePudding user response:

Instead of using jsonPayload, try logging reaction instead. I think jsonPayload is the JSON that is supplied to the logger function.

  • Related