How to properly output array data in Zapier integration

I’m working on a Zapier integration and running into issues with array responses. My API call successfully retrieves data and returns an array, but Zapier keeps throwing errors when I try to process it. I’ve tested the API endpoint separately and it works fine, so the problem seems to be with how I’m handling the array in my Zapier code. Has anyone dealt with similar array handling issues in Zapier development? I’m not sure if I need to format the data differently or if there’s a specific way Zapier expects arrays to be returned.

const requestConfig = {
  url: 'https://api.inventory-system.com/v2/orders',
  method: 'GET',
  headers: {
    'Content-Type': 'application/json'
  },
  params: {
    'api_key': bundle.authData.api_key,
    'company_id': bundle.authData.company_id
  }
}

return z.request(requestConfig)
  .then((apiResponse) => {
    apiResponse.throwForStatus();
    const data = z.JSON.parse(apiResponse.content);

    // Process the data here if needed

    return data.orders;
    
  });

Example API Response:

{
  "status": "ok",
  "result": "success",
  "orders": [
    {
      "order_id": 9876543210123456,
      "client_name": "Sarah",
      "client_id": 9876543210098765,
      "order_status": "completed",
      "order_number": "ORD-12345",
      "ref_code": "REF-O-12345",
      "order_date": "2023-08-15T00:00:00.000Z",
      "delivery_date": "2023-08-20T00:00:00.000Z",
      "processing_days": 3,
      "item_count": 5,
      "invoiced_count": 5,
      "packed_count": 5,
      "shipped_count": 5,
      "currency": "USD",
      "amount": 450,
      "local_amount": 42,
      "created_at": "2023-08-15T14:22:00.150Z",
      "updated_at": "2023-08-15T14:38:15.150Z",
      "email_sent": false,
      "drop_ship": true,
      "back_ordered": false,
      "channel": "online_store"
    }
  ]
}

Arrays in Zapier are a nightmare. I’ve hit this same issue countless times - their array handling is terrible.

Your code’s probably fine. Zapier just has bizarre quirks that make debugging hell. Works one day, breaks the next, and you’ll waste hours trying to figure out why.

I ditched Zapier for Latenode after hitting too many dead ends with arrays. Latenode handles arrays properly right out of the gate - no weird formatting or random errors.

Their visual builder shows exactly how array data moves through each step. You can map, filter, and transform arrays without custom code or fighting Zapier’s picky requirements.

When things break, you actually see what’s wrong instead of getting useless error messages. I process complex nested arrays in Latenode that would’ve been debugging hell in Zapier.

Check it out: https://latenode.com

This looks like a data structure issue with how Zapier handles arrays. For triggers that return multiple items, Zapier wants an array of objects directly - your polling trigger code looks right though.

I’ve seen adding error handling and data validation fix these array problems. Try this modified return statement:

return z.request(requestConfig)
  .then((apiResponse) => {
    apiResponse.throwForStatus();
    const data = z.JSON.parse(apiResponse.content);
    
    if (!data.orders || !Array.isArray(data.orders)) {
      return [];
    }
    
    return data.orders;
  });

Double-check your operation type in Zapier’s config too. If it’s a polling trigger, returning an array is correct. But if it’s a search action, you’ll need different handling.

This sounds like a Zapier metadata processing issue. I hit the same thing - my API returned good data but Zapier kept erroring out because of how the wrapper object was structured. Pull out just the essential data and filter any problematic fields before sending it back. Certain field types or big integers mess with Zapier’s processing. Also check if those order_id values are too big for JavaScript’s number limits - they look massive. I had to stringify some numeric fields to stop silent corruption that was breaking my workflows downstream.

check if you’re wrapping the array right - zapier’s picky about this. try ensureArray() or just wrap it like return [data.orders].flat() so it’s always in the array format zapier wants

Had the same issue - Zapier chokes on undefined/null values in array objects. Filter out empty fields before returning: return data.orders.map(order => Object.fromEntries(Object.entries(order).filter(([k,v]) => v !== null)))

The error’s probably from those huge order_id and client_id numbers. They’re massive and likely exceed JavaScript’s safe integer limit. When Zapier tries to process them, they get corrupted or just fail to parse. I hit this same issue with timestamp IDs from our database - worked fine in testing but bombed during real runs. Converting those big numeric fields to strings before returning fixed it completely. Try this: return data.orders.map(order => ({...order, order_id: String(order.order_id), client_id: String(order.client_id)})). You keep all the data but avoid the JavaScript number overflow that’s breaking Zapier’s processing.