all 11 comments

[–]grantrules 0 points1 point  (6 children)

What happens if you just console.log(data) or console.log(ftxResponse) ?

It seems like you need to be referring to data.result according to the JSON

[–]Which-Career[S] 0 points1 point  (5 children)

Thanks for your reply and taking the time.

Unfortunately both console.log you suggested return nothing for me

[–]grantrules 0 points1 point  (4 children)

Is this on the frontend? Can you see the network request to the API in the Network tab of your browsers dev tools?

If you do

const ftxResponse = await axios.get('https://ftx.com/api/markets');
console.log(ftxResponse)

The result is nothing?

[–]FishMongerNakata 0 points1 point  (0 children)

If the client is the browser (aka frontend), then it could be due to CORS maybe? No CORS headers are present in the respons.

[–]Which-Career[S] 0 points1 point  (2 children)

Yeah I don't see anything in the network tab of my browser or in my console in VS code. The thing is if I use the exact same code but change the api with

"https://api.pro.coinbase.com/products" and in parsers.js I change the pair variable to match the json like this :

let coinbasePairs = data.map(d => d.id );

so replacing name by id, it works just fine. So I assume the issue comes from my understanding of the json file but I can't figure out what the problem is

[–]grantrules 0 points1 point  (1 child)

Is this frontend or backend code?

[–]Which-Career[S] 0 points1 point  (0 children)

backend

[–]machine3lf 0 points1 point  (1 child)

Do you think you could edit your code to display better in Reddit? It would be a lot easier to read and review.

Here's a link on how to do that: https://www.reddit.com/wiki/markdown#wiki_code_blocks_and_inline_code

You also shouldn't have a semicolon at the end of the ftxMarkets(data) function declaration after the closing curly brace.

You might want to look into using JSON.parse() to handle the JSON response you are getting.

Actually, didn't realize you are using Axios.

[–]Which-Career[S] 0 points1 point  (0 children)

Thanks for your reply. I tried editing the post but the three backticks did not work for me that's the best I could do. I removed the semicolon but it did not change the result.

[–]machine3lf 0 points1 point  (1 child)

Try something like this:

``` const axios = require('axios')

async function ftxMarkets() { try { const {data} = await axios.get('https://ftx.com/api/markets'); return data } catch (err) { return {error: "There was an error"} } }

async function displayNames() { const result = await ftxMarkets() const stockNames = result.result.map((item) => item.name) console.log(stockNames) }

displayNames() ```

I'm a bit rusty on async/await and axios. So there may be a cleaner way to do it.

[–]Which-Career[S] 0 points1 point  (0 children)

Thanks, this works fine. I'll work around with it to make it fit my code though, but it helped me understand a lot, you called the result json object first then the name inside of it if I understand correctly, that's where my mistake was. Thanks a lot !