I'm trying to get data from an API using Axios. I have two API calls. The first call runs fine, and I get the data I expect. The second one, however, comes back with the 400 error bad request.
I've searched through multiple forums to try and find a solution, but I don't quite understand the code that I find.
const [player, setPlayer] = useState([]);
const [newPlayer, setNewPlayer] = useState([]);
const FindLoadout = async () => {
await axios.get(`http://api.paladins.com/paladinsapi.svc/getmatchidsbyqueueJson/${devId}/${generateSignature('getmatchidsbyqueue')}/${props.sess}/${moment.utc().format('YYYYMMDDHHmmss')}/428/${moment.utc().format('YYYYMMDD')}/-1,00`).then((response) => {
const playerData = response.data;
playerData.map((el) => {
player.push(el.Match)
})
console.log(player);
for(let i = 0; i < 50; i++) {
newPlayer.push(player[i]);
}
console.log(newPlayer);
}).catch((error) => {
console.log(error);
});
axios.get(`http://api.paladins.com/paladinsapi.svc/getmatchdetailsbatchJson/${devId}/${generateSignature('getmatchdetailsbatch')}/${props.sess}/${moment.utc().format('YYYYMMDDHHmmss')}/${newPlayer.join(",")}`).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
}
The error message is:
Error: Request failed with status code 400 at createError (createError.js:17) at settle (settle.js:19) at XMLHttpRequest.handleLoad (xhr.js:60)
player
andnewPlayer
aren't defined. – Brandon HillgenerateSignature
etc., but you're not using theuseState
hook correctly. The second value it returns is how it's supposed to be updated, like:setPlayer(myUpdatedValue)
: reactjs.org/docs/hooks-state.html – Brandon Hill