#API JSON discord.js (undici)
21 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
What‘s apiURLW defined as?
https://albion-online-data.com/api/v2/stats/gold?count=1
That api doesn’t return an object with a listW property it seems
Only an array containing one object with price and timestamp property
How can I access it ?
I tried to do console.log(listW[0]) yet it gave an error
The await …json() returns this👆
Surely you know how to work with arrays and objects?
Because there is no listW to destructure from the JSON
I am not familiar with node.js tbh , learning
Any idea how can I get access to that API , as most of them have the same structure
An Array with an object inside
You already do get access to it. You just need to not destructure from it
Destructuring assignment
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
Don’t do that👆
Instead assign without destructuring
you mean I have to remove this line const { listW } = await goldW.body.json();
I tried to do this :
const goldW = await request(`${apiURLW}`);
console.log(goldW[0].price);
it gave undefined
You still have to .body.json(), but assign it to a variable like const listW = without the {} destructure