I’m trying to process Genesys Cloud webhook events in a Node.js Lambda. The function throws a SyntaxError when parsing the body because it’s receiving a string instead of an object. Here is the handler code:
exports.handler = async (event) => {
const payload = JSON.parse(event.body);
console.log(payload.data);
return { statusCode: 200 };
};
The event body arrives as a raw string. I need to handle the case where body is null or already parsed. What is the correct way to safely extract the data array from the webhook event?