I am building a zapier integration for an app. The app returns a JSON response like this...
{
result: "Success",
message: "Showing a total of 1 bookings",
bookings: {
42: {
event: {
event_name: "Chris's Event",
event_date_uk: "Saturday 22nd Jun 2019"
}
}
}
}
In my zapier parser, I have the following....
const options = {
url: bundle.authData.url+`/api/v1/bookings`,
method: 'GET',
headers: {
'Accept': 'application/json'
},
params: {
'key': bundle.authData.api_key,
'secret': bundle.authData.client_secret,
'booking_id': 42,
'scope': 'full'
},
}
return z.request(options)
.then((response) => {
response.throwForStatus();
const results = z.JSON.parse(response.content);
return results["bookings"];
});
However, when I test, I get the following....
Results from triggers.new_booking.operation.perform
must be an array of objects. We got {"42": {"event": {"event_name": "Chris's Event", "event_date_uk": "Saturday 22nd Jun 2019"}}}
.
I thought JSON.parse did return an object? And from what I can see I have returned an array of objects. Any ideas what Im doing wrong?
This contains an array of objects (bookings):
{
"result": "Success",
"message": "Showing a total of 1 bookings",
"bookings": [
{
"42": {
"event": {
"event_name": "Chris's Event",
"event_date_uk": "Saturday 22nd Jun 2019"
}
}
}
]
}
Edit: To access the event property in your JSON it's bookings.42.event
where in JSON above it's bookings[0].42.event
.