Zapier Raw Webhook Handler - JSON Object Parsing Error

I’m trying to set up a connection between two CRM systems (Salesforce and HubSpot) through Zapier webhooks. The first system sends JSON data to my webhook that looks like this:

{
    "campaignId": 2847591037,
    "users": [
        {
            "user_data": {
                "SMS-enabled": true,
                "push-notifications": true,
                "jobTitle": "MANAGER",
                "phoneNumber": "987654321098",
                "fullName": "John Anderson",
                "prefix": "Dr",
                "surname": "Anderson",
                "sex": "M",
                "accountType": "Premium Customer",
                "email-enabled": true,
                "firstName": "John",
                "lastIP": "192.168.1.100",
                "timezone": "GMT+0300",
                "overseas": "no",
                "isPremium": true,
                "emailAddress": "[email protected]",
                "userId": 28491
            },
            "recordId": "a45b7fg8h9j0k1l2m3n4o5p6q7r8s9t0",
            "linked_ids": [
                "28491",
                "[email protected]"
            ],
            "primaryEmail": "[email protected]",
            "mainId": "28491"
        }
    ]
}

I’m having trouble accessing the users array in my JavaScript code step. When I try to get the first user object with this code:

var data = JSON.parse(JSON.stringify(inputData));
console.log(data.users[0]);
return data;

I keep getting “TypeError: Cannot read property ‘0’ of undefined”. The Raw Hook seems to receive the JSON correctly but I can’t access the nested array elements. How can I properly handle this webhook data to extract values from users[0]?

i had this issue too! try logging the whole inputData to check its structure. sometimes zapier alters the data format. use console.log(JSON.stringify(inputData)) to see it fully then adjust how you access the users array.

The error means your webhook data structure isn’t what you expect. Don’t assume the users array exists - add some defensive checking first. Try: if (inputData && inputData.users && inputData.users.length > 0) { console.log(inputData.users[0]); } This’ll show you exactly where things break. Also check if Zapier’s getting the webhook as raw payload vs parsed JSON - sometimes you need inputData.rawBody and parse it yourself. I’ve seen the webhook content-type header mess with how Zapier processes incoming data, so make sure that’s set to application/json on your end.

This sounds like a Zapier webhook wrapping issue. I’ve run into this before - Zapier usually nests the incoming JSON under extra properties. Try inputData.body.users[0] or inputData.data.users[0] instead. Drop the JSON.parse(JSON.stringify()) wrapper too - inputData’s already parsed. Zapier code steps get JavaScript objects, not JSON strings. Console log Object.keys(inputData) first to see what’s actually available at the top level.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.