I’m trying to set up a connection between two CRM systems using Zapier and webhooks. The source CRM sends JSON data, but I’m running into issues parsing it correctly in Zapier.
When I use a Catch Raw Hook, the JSON seems to come through fine. But when I try to access the data in a Code step, I get an error saying it can’t read the ‘profiles’ property.
Here’s a simplified version of what I’m trying:
function parseWebhookData(input) {
const data = JSON.parse(input);
return data.profiles[0];
}
const result = parseWebhookData(inputData);
console.log(result);
This gives me a ‘TypeError’. I’ve also tried using a regular Catch Hook, but that seems to change the structure of the data in a way I can’t easily work with.
Does anyone know how to correctly handle and parse webhook data in Zapier? I just need to access the first item in the ‘profiles’ array. Any help would be appreciated!
have u tried using JSON.parse() on the inputData before accessing it? sometimes zapier doesn’t auto-parse the json for u. also, make sure ur webhook is actually sending valid json. u can use a tool like jsonlint to check. if that doesn’t work, maybe try logging the input to see what ur actually getting from the webhook
I’ve dealt with similar JSON parsing issues in Zapier before. One thing that often trips people up is that Zapier sometimes modifies the incoming data structure. Have you checked what the raw input looks like?
Try adding a ‘Print’ action right after your webhook trigger and examine the output. You might find that Zapier has wrapped your JSON in another object, like inputData.body or inputData.raw.
If that’s the case, you’ll need to adjust your parsing code. Something like this might work:
function parseWebhookData(input) {
const rawData = input.body || input.raw || input;
const data = typeof rawData === 'string' ? JSON.parse(rawData) : rawData;
return data.profiles[0];
}
This approach handles different ways Zapier might structure the input. It’s been a lifesaver for me in several projects. Let me know if this helps or if you need more guidance!
I’ve encountered similar issues with Zapier webhooks before. One solution that worked for me was using the ‘Catch Hook’ action instead of ‘Catch Raw Hook’. This automatically parses the JSON for you. Then, in your Code step, you can directly access the data without parsing:
function getFirstProfile(input) {
return input.profiles[0];
}
const result = getFirstProfile(inputData);
console.log(result);
If that doesn’t work, you might need to check the structure of your incoming data. Sometimes, webhooks wrap the payload in an additional object. Try logging inputData
to see its exact structure. You might need to adjust your code accordingly, like inputData.body.profiles[0]
if there’s an extra layer.