I’m working with Zapier and running into an issue with how it processes API responses. When I make a webhook request to fetch data, Zapier seems to automatically flatten or restructure the JSON response in a way that makes it difficult to work with.
The original API returns a nested JSON structure like this:
{
"messages": [
{
"message_id": 87654321,
"content": "Welcome to our service",
"image_url": null,
"location_data": null,
"platform": "telegram",
"direction": "incoming",
"is_viewed": false,
"timestamp": "2023-05-15T14:30:22 UTC",
"voice_note": null,
"document_file": null,
"external_ref": null,
"delivery_info": null,
"agent_id": 5432,
"room_id": 2108,
"conversation_id": 445566,
"user_id": 998877
},
{
"message_id": 87654322,
"content": "Support agent online",
"image_url": null,
"location_data": null,
"platform": "telegram",
"direction": "automated",
"is_viewed": false,
"timestamp": "2023-05-15T14:30:22 UTC",
"voice_note": null,
"document_file": null,
"external_ref": null,
"delivery_info": null,
"agent_id": null,
"room_id": 2108,
"conversation_id": 445566,
"user_id": 998877
}
]
}
But Zapier transforms this into a flattened format that’s hard to parse. Is there a way to preserve the original structure or work around this behavior? Any suggestions would be helpful.
Yeah, this is one of Zapier’s most annoying quirks with complex API responses. I’ve hit the same wall with nested arrays from different APIs. What worked for me was dropping a Code by Zapier step right after the webhook trigger. You can grab the raw response with inputData and parse it with JavaScript before Zapier’s flattening kicks in. Try JSON.parse(inputData.raw_body) to get the original structure back. If your API allows it, consider tweaking the endpoint to return data that plays nicer with Zapier. I’ve had better luck with key-value pairs instead of nested arrays when I can swing it. Also check if the webhook’s raw output keeps more of the original structure intact - sometimes you can access that directly in later steps.
Had this exact same issue last month with a different API. Here’s what worked for me: set up a test webhook with Webhook.site or RequestBin first. You’ll see exactly what Zapier’s getting vs what your API’s actually sending. Half the time, Zapier flattens stuff because it’s misreading the content type or headers. Once I figured that out, I threw in a Parser by Zapier step and configured it specifically for JSON arrays. You can map each array element to separate line items, then use those downstream. The trick is telling the parser to expect multiple records in your messages array instead of letting Zapier wing it. Kept all my nested data intact and made everything accessible for the rest of the workflow.
This is frustrating but here’s a workaround that works for me. Don’t let Zapier handle the parsing directly. Use a formatter step with ‘utilities > line item to text’ first, then add a code step to rebuild your JSON properly. Also double-check your webhook’s content-type header - it can mess with how Zapier processes responses.