One answer for post request said to stringify the JSON payload, but I am sending a get request
var list= [ "bitcoin","ethereum","litecoin","dogecoin","stellar","cardano","tezos","0x","uniswap"]
var url = "https://api.coingecko.com/api/v3/simple/price?ids="+list.join(",")+"&vs_currencies=usd"
var headers={ "accept": "application/json", "muteHttpExceptions":true}
var response = JSON.parse(UrlFetchApp.fetch(url,headers));
Logger.log(response)
The error occurs at line 4.
I thought maybe I should stringify the headers , so I did JSON.parse(UrlFetchApp.fetch(url, JSON.stringify(headers))) But it raised the exception Bad Value at this same line
The problem is that, the initial code is running fine for most of the times, but sometimes it raises that exception
This is because you have the response object and not the string data..
var response = JSON.parse(UrlFetchApp.fetch(url,headers));
//to:
var response = UrlFetchApp.fetch(url,headers);
var data = JSON.parse(response.getContentText());