Reputation: 615
For the Zapier App that I am developing, I am configuring a Trigger of type REST Hook.
Say that my API posts details about soccer matches. The format of the data that gets posted to Zapier by my API would look something like this:
[{
"game_start_time": "2020-06-26",
"home_score": 2,
"away_score": 1,
"goals": [
{
"time": "45+2",
"player_name": "Lionel Messi",
"team": "home"
},
{
"time": "65",
"player_name":"Cristiano Ronaldo",
"team": "away"
},
{
"time": "90+5",
"player_name": "Lionel Messi",
"team": "home"
}
],
"attendance": 76000,
"penalties": [
{
"time": "21",
"player_name":"Cristiano Ronaldo",
"type": "yellow",
"reason": "diving"
}
]
}]
The output fields are specified as follows:
I want to be able to allow a user of my App to consume all the output fields available from my API, including goals
and penalties
. When I try to specify these output fields, there doesn't seem to be a way for me to get the objects in the array separately.
For example:
goals: [{
"time": "45+2",
"player_name": "Lionel Messi",
"team": "home"
},
{
"time": "65",
"player_name":"Cristiano Ronaldo",
"team": "away"
},
{
"time": "90+5",
"player_name": "Lionel Messi",
"team": "home"
}]
goals[]time: "45+2, 65, 90+5"
goals[]player_name: "Lionel Messi, Cristiano Ronaldo, Lionel Messi"
goals[]team: "home, away, home"
It seems that it would be difficult for a Zap using my Zapier App Trigger to consume penalties
and goals
unless they add their own custom code to parse my Trigger's data.
Upvotes: 1
Views: 588
Reputation: 126
This is a tricky situation, I believe it's related to how Zapier handles responses with nested arrays (AKA "line items" on our platform) within Zapier as a whole. That is, it's not really specific to your app/integration, per se.
By default, each key/value will get turned into a field. Any key which has an array of objects will give back individual fields as "line items" which is why you see the comma-separated values for things like goals[]Time and so on.
As it is right now, You can use a Line Item to Text Formatter step as outlined at https://zapier.com/help/create/format/get-started-with-formatter
But in this case, I'd recommend transforming the Goals and Penalties array into a top-level array with all of the data flattened within it and added to the object that the trigger is sending to the action step. You will need to do this when handling the results from the trigger as part of your dev app.
Upvotes: 2