I'm sending a POST
request to a HTTP Firebase Cloud Function endpoint which contains the following body:
{
"securityContext": "edbsne0f17660e9ab49ad9bc3ddd4656230e0a9304bd15916f595b793da9109e1f7aa61e76c4afa91319011a7259b24ed583302334e22c5544c4e00506cf2fed93b28434e4088b22dda02712adf63bb6a370f",
"event": "onInstall",
"orgId": "7001935574",
"dc": "AU"
}
But when I try to access any of those properties it shows undefined
. The entire body is also undefined
.
This is what my onRequest
HTTP Cloud Function endpoint looks like. It also shows my other failed attempts of getting the body data, which I have commented out:
export const getZohoDeskCallBack = functions.https.onRequest((req, res) => {
const body = req.body;
functions.logger.info('body', body);
const rawBody = req.body;
functions.logger.info('rawBody', rawBody);
// Other attempt 1:
// const bodySecurityContext = req.body.securityContext;
// functions.logger.info('bodySecurityContext', bodySecurityContext);
// Other attempt 2:
// const rawBodySecurityContext = req.rawBody.securityContext;
// functions.logger.info('rawBodySecurityContext', rawBodySecurityContext);
// Other attempt 3:
// const reqBodyToJSON = req.body.toJSON();
// functions.logger.info('req.body.toJSON()', reqBodyToJSON);
// Other attempt 4:
// const reqRawBodyToJSON = req.rawBody.toJSON();
// functions.logger.info('req.rawBody.toJSON()', reqRawBodyToJSON);
// Other attempt 5:
// const reqBodyToJSONparse = JSON.parse(req.body);
// functions.logger.info('reqBodyToJSONparse', reqBodyToJSONparse);
// Other attempt 6:
// const reqRawBodyToJSONparse = JSON.parse(req.rawBody);
// functions.logger.info('reqRawBodyToJSONparse', reqRawBodyToJSONparse);
// Other attempt 7:
// const reqBodyToJSONparse = req.body.toString();
// functions.logger.info('reqBodyToJSONparse', reqBodyToJSONparse);
// Other attempt 8:
// const reqRawBodyToJSONparse = req.rawBody.toString();
// functions.logger.info('reqRawBodyToJSONparse', reqRawBodyToJSONparse);
// Other attempt 9:
// const reqBodyToJSONparse = req.body.toString();
// const securityContext = reqBodyToJSONparse.securityContext;
// functions.logger.info('securityContext', securityContext);
res.end();
});
You can see a test of the POST
request here and here.
Apparently, if a request has a content-type
of application/json
Firebase Cloud Functions will automatically parse the JSON and put it into the body
property.
But as you can see from those tests linked above the header content-type
is empty or missing. Also I am unable to change the POST
request because I have no control over that.
Maybe that could be the issue? If so, I thought I could access it from the rawBody
property, but that also doesn't work.
I have been pulling my hair out trying to solve this. Any help would be much appreciated.