I am creating Netlify function and I want to access the event.body objects (especially the event.body.mode/requestBody.mode) but console.log gives me undefined.
exports.handler = async function (event) {
const requestBody = event.body;
console.log(requestBody);
console.log(requestBody.mode);
let variableX = requestBody.mode;
return {
headers: {
"content-type": "application/json",
},
statusCode: 200,
body: JSON.stringify({"message":variableX}),
};
};
Here is the Function log:
Aug 4, 09:28:19 PM: 4870e164 INFO {"eventName":"shippingrates.fetch","mode":"Live"}
Aug 4, 09:28:19 PM: 4870e164 INFO undefined
I have tried to JSON.parse the event.body but it returns an error. Not parsing works.
I also tried requestBody['mode']
but still no luck.