Can anyone clarify the correct way to parse the nested event data when consuming a Genesys Cloud webhook in a Node.js Lambda function? i am writing a consumer for the routing.queue.member.updated event. the documentation shows the payload structure, but when i log the event object in the lambda handler, the structure seems different than expected.
i am using the standard aws lambda nodejs runtime. here is my current handler code:
exports.handler = async (event) => {
console.log('received event:', JSON.stringify(event, null, 2));
// trying to access the queue id
const queueId = event.body.queue.id;
// this throws typeerror: cannot read property 'queue' of undefined
console.log('queue id:', queueId);
return {
statusCode: 200,
body: 'processed'
};
};
the error i am getting is TypeError: Cannot read property 'queue' of undefined. when i check the cloudwatch logs, the event.body is a string, not an object. i have to parse it first. but even after parsing JSON.parse(event.body), the structure is still not matching the api documentation examples. the documentation says the payload should be:
{
"id": "abc-123",
"queue": {
"id": "queue-xyz",
"name": "support"
}
}
but in the lambda, after parsing the body, the object looks like:
{
"event_id": "def-456",
"event_type": "routing.queue.member.updated",
"data": {
"queue": {
"id": "queue-xyz"
}
}
}
so the actual data is nested under data. is this specific to the webhook delivery format vs the api response format? i am trying to build a robust parser that can handle this without hardcoding paths. should i be using the event.data property instead? or is there a standard library i should use to normalize this? i am building a typed python client for other services, but for this integration, i am stuck on the node side. any advice on how to reliably extract the queue.id from this payload structure?