Trying to parse the event object in a Node Lambda triggered by Genesys Cloud webhooks. The body comes in as a string, so I have to JSON.parse it first, but the structure seems nested differently than the docs suggest. Here’s what I get after parsing: { “events”: […] }. Not sure if I should be looping through events or looking at the root level. Also seeing some 4xx errors on the retry side. Any tips?
the webhook payload structure changed a while back. you’re seeing events because Genesys batches multiple events into a single POST when traffic spikes. if you only look at the root, you’ll miss data.
here’s a quick snippet for your Lambda handler. it handles the batch and ensures you return 200 immediately so Genesys doesn’t retry.
exports.handler = async (event) => {
try {
const body = JSON.parse(event.body);
const events = body.events || [body]; // fallback for single event payloads
for (const evt of events) {
// process evt here
console.log(evt.eventType);
}
return { statusCode: 200, body: 'OK' };
} catch (err) {
// return 4xx to trigger retry, but log the error
console.error(err);
return { statusCode: 400, body: 'Parse Error' };
}
};
don’t forget to check event.httpMethod if you’re using API Gateway. Genesys sends POST for payloads but might GET for health checks if you configured it that way. the 4xx errors are likely because your Lambda is timing out before returning the success response. Genesys waits 5 seconds. keep it snappy.