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:
Reference: