CoinMarketCap API retrieval

Hello!

I’ve been trying to “axios.get()” updated news regarding coinmarketcaps top 10 coins. I keep getting an error message and I can’t figure what adjustment I need to make… Can anyone help?

Here is my code

const coinInfo = async() => {
  //fetch coin update data thorugh RANK
  const apiKey = {
    key: '68da4c90-613d-4068-8f6d-0e7dfeff457c'
  };
  const response = await axios.get('https://pro-api.coinmarketcap.com/v1/cryptocurrency/info/CMC_PRO_API_KEY=' + apiKey.key);
  const coinInformation = response.data.slice(0, COIN_COUNT).map(coin => coin.info);
  const promises = coinInformation.map(info => info.data.urls);
  const coinNews = await Promise.all(promises);
  const coinNewsData = coinNews.map(function(response) {
    const info = response.data;
    return{
      key: info.id,
      info: info.message_board,
    };
  });
  setcoinNews(coinNewsData);
}

And here is my error…

GET https://pro-api.coinmarketcap.com/v1/cryptocurrency/info/CMC_PRO_API_KEY=68da4c90-613d-4068-8f6d-0e7dfeff457c 404

createError.js:16 Uncaught (in promise) Error: Request failed with status code 404
    at createError (createError.js:16)
    at settle (settle.js:17)
    at XMLHttpRequest.handleLoad (xhr.js:62)

The API key should be added as a query parameter and not a path in the URL.

The right way to call it would be - https://pro-api.coinmarketcap.com/v1/cryptocurrency/info?CMC_PRO_API_KEY=68da4c90-613d-4068-8f6d-0e7dfeff457c&id=1

I also added “id” because it is needed to mention which crypto you’d like the info of. 1 points to bitcoin.

Hope this helps.

Thanks

Thanks malik,

I’m still having a hard time having it properly fetch the data… is my code above correct, with the proper adjustment made to axios.get() that you mentioned? It still isn’t fetching any data for me…

Just change this statement into this -

const response = await axios.get(`https://pro-api.coinmarketcap.com/v1/cryptocurrency/info?CMC_PRO_API_KEY=${apiKey.key}&id=1`)

This should work.