Genesys Cloud Webhook Payload Parsing in Node.js Lambda

Setting up a Lambda to catch Genesys Cloud interaction events. The webhook hits the endpoint, returns 200, but the payload parsing inside the handler is flaky. Sometimes event.body is a string, sometimes it’s already an object, and the data field is nested deeper than the docs imply.

Here’s the handler skeleton:

exports.handler = async (event) => {
 console.log('Raw event:', JSON.stringify(event));
 
 let body;
 try {
 body = typeof event.body === 'string' ? JSON.parse(event.body) : event.body;
 } catch (e) {
 console.error('Parse error:', e);
 }

 // Docs say data is in body.data, but it's often in body.data[0].details
 const interactionId = body?.data?.[0]?.details?.interactionId;
 
 if (!interactionId) {
 return {
 statusCode: 200, // Must return 200 or GC retries
 body: 'Missing ID'
 };
 }
 
 // ... process interactionId
 return { statusCode: 200 };
};

The issue is that body.data is sometimes an array, sometimes a single object, depending on the event type (e.g., conversation:updated vs interaction:created). The docs are vague on this.

  • Node.js 18 runtime
  • API Gateway REST API (not HTTP API)
  • Webhook payload size ~2KB

Anyone have a solid pattern for normalizing these payloads before processing? I’m tired of adding extra null checks for every event type.