I’m not really a developer but I need some help with JSON data manipulation in Zapier.
I’m working with a gaming stats API that sends back player match data. The problem is that the API response includes information for multiple matches (around 10 records) but I only need the most recent one for my automation.
Here’s my current code setup:
axios.get('https://api.gameserver.com/v2/player/87654321/matches/recent?token=<secret_key>')
.then(function(response) {
return response.data;
})
.then(function(data) {
output(null, data);
})
.catch(output);
The API returns something like this:
{
"playerId": 87654321,
"matches": [
{
"matchId": 9876543210,
"valid": true,
"mode": "RANKED",
"type": "COMPETITIVE",
"category": "SOLO_QUEUE",
"arena": 1,
"side": "blue",
"character": 45,
"ability1": 7,
"ability2": 12,
"playerLevel": 30,
"pointsGained": 89,
"timestamp": 1675234567890,
"performance": {
"finalLevel": 16,
"goldCollected": 12450,
"deaths": 3,
"creepsKilled": 156,
"eliminations": 7,
"goldUsed": 11200,
"totalDamage": 34567,
"damageTaken": 28901,
"team": "blue",
"victory": true,
"equipment1": 2001,
"equipment2": 2045,
"equipment3": 3078,
"assists": 12
}
},
{
"matchId": 9876543209,
"valid": true,
"mode": "RANKED"
}
]
}
In Zapier the data shows up as nested arrays and I can see all the match records. I just want to grab the first match entry and its stats. How can I modify my code or add another step to extract only the initial array element? Any simple solution would be great.