79182459

Date: 2024-11-12 19:28:02
Score: 0.5
Natty:
Report link

Getting Specific Crypto Prices using CMC API

I tried your code and it seems to be missing and it has an error. I modified and converted your python into Javascript and added the forEach() function to iterate each data if the ID is matched in your array it will return the CRYPTO value of EURO as to match in your script json.data[x].quote.EUR.price.

Code.gs

function getCryptoData(id) {
  var url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?convert=EUR";
  var apiKey = 'xyz'; // Replace with your API key
  var headers = {
    "X-CMC_PRO_API_KEY": apiKey,
    "Accept": "application/json"
  };

  var response = UrlFetchApp.fetch(url, { 'headers': headers });
  var json = JSON.parse(response.getContentText());
  json.data.forEach(x => {
    if (x.id == id) {
      console.log(x.name, x.quote.EUR.price)
      return x.quote.EUR.price
    }
  })
}

Sample Output:

Sample 1 Sample 2

Reference:

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Lime Husky