My Lambda function processes Genesys Cloud webhooks but throws a SyntaxError: Unexpected end of JSON input. The event body is undefined for some events. I’m using JSON.parse(event.body) without checking if it exists. How do I handle the missing body gracefully?
Try guarding the parse call first.
const data = event.body ? JSON.parse(event.body) : {};
Genesys sometimes sends empty payloads for certain event types, so that check prevents the crash.