Zapier trigger expects array format but receives object from API response

I’m working on a Zapier integration and running into an issue with the data format. My API sends back data in this structure:

{
  status: "OK",
  info: "Found 1 reservation",
  reservations: {
    78: {
      details: {
        title: "Team Meeting",
        scheduled_date: "Monday 15th May 2023"
      }
    }
  }
}

Here’s my Zapier code that processes this response:

const requestConfig = {
  url: bundle.authData.endpoint + `/api/v2/reservations`,
  method: 'GET',
  headers: {
    'Content-Type': 'application/json'
  },
  params: {
    'api_key': bundle.authData.access_key,
    'token': bundle.authData.secret_token,
    'reservation_id': 78,
    'details': 'complete'
  },
}

return z.request(requestConfig)
  .then((response) => {
    response.throwForStatus();
    const data = z.JSON.parse(response.content);
    
    return data["reservations"];
  });

But Zapier throws an error saying it needs an array of objects, not the object I’m returning. The error shows the exact object structure but says it’s not in the right format. I thought I was returning the correct data type but apparently not. What am I missing here?

yeah, classic zapier gotcha. your api’s returning an object but zapier polling triggers need arrays. quick fix: wrap it in Object.values() like return Object.values(data.reservations). just heads up - you’ll lose the reservation ID unless you merge it back in.

I hit the same issue building my first Zapier integration. Zapier triggers need arrays, but your API sends back reservations as an object with numeric keys. You need to transform that object into an array format. Here’s how you can flatten it and add the reservation ID to each item: javascript return z.request(requestConfig) .then((response) => { response.throwForStatus(); const data = z.JSON.parse(response.content); const reservationsArray = Object.entries(data.reservations).map(([id, reservation]) => ({ reservation_id: id, title: reservation.details.title, scheduled_date: reservation.details.scheduled_date })); return reservationsArray; }); This flattens your nested structure and makes it way easier to work with in Zapier. Object.entries is perfect when you need both the key and value from your original object.

Zapier needs an array for triggers, but you’re sending an object with reservation IDs as keys. Your API returns reservations as an object (with keys like 78), not an array.

You need to convert that object to an array. Here’s how to fix your return statement:

return z.request(requestConfig)
  .then((response) => {
    response.throwForStatus();
    const data = z.JSON.parse(response.content);
    
    const reservationsObj = data["reservations"];
    const reservationsArray = Object.keys(reservationsObj).map(id => {
      return {
        id: id,
        ...reservationsObj[id]
      };
    });
    
    return reservationsArray;
  });

This converts your object into an array Zapier can handle. Each reservation becomes an array element with the ID as a property.