Workflow works with test data, but not with webhook

I have a webhook that is receiving JSON data. I have checked to ensure JSON data is formatted correctly. If I copy the JSON data from a failed webhook attempt, and paste that JSON data into the test data in the workflow, the workflow works fine. But, when that same JSON data is sent to the webhook, I get a Javascript error:

Error evaluating JSONtripCode: TypeError: Cannot read properties of undefined (reading 'recording')

The line in question is:
const bucketName = jsonPayload.data.recording.bucket.name;

startTrigger is the name of the webhook trigger.
jsonPayload is defined above the problematic line as:
const jsonPayload = startTrigger.data

Can anyone point me in the right direction as to why this would work in testing, but fail in practice?

3 Likes

Hi @AIM_Rhys ,

You can directly access nested keys of startTrigger.data by storing it in a variable. This allows you to navigate the nested structure of the JSON data.
Here's the corrected code: const bucketName = jsonPayload.recording.bucket.name;

Feel free to ask if you need further assistance or have additional questions. We're here to help!

5 Likes

Thank you for this! Do you have any theories why my original code worked with test data, but not with an actual webhook event? It seems to me that I should have gotten the same error either way.

1 Like