Home > Back-end >  JSON on Google Sheets: Exception: Attribute provided with no value: url
JSON on Google Sheets: Exception: Attribute provided with no value: url

Time:12-07

I'm trying to import Crypto Data into Google Sheets. In the Apps Script there occours the following error:

Exception: Attribute provided with no value: url
ImportJSONAdvanced  @ ImportJSON.gs:168
ImportJSON  @ ImportJSON.gs:63

Also when I try to diplay data in the sheet withi this formula:

=importJSON("https://api.coingecko.com/api/v3/coins/markets?vs_currency=eur&ids=bitcoin")

i get the error "#NAME?"

Can anybody help me with this?

Here the 2 snippets that cause the errors:

function ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeFunc, transformFunc) {
var jsondata = UrlFetchApp.fetch(url, fetchOptions);   *<--- ERROR OCCOURS HERE
var muteHttpExceptions = true;
var object   = JSON.parse(jsondata.getContentText());
return parseJSONObject_(object, query, parseOptions, includeFunc, transformFunc);
}
function ImportJSON(url, query, parseOptions) {
  return ImportJSONAdvanced(url, null, query, parseOptions, includeXPath_, defaultTransform_); //   *<--- ERROR OCCOURS HERE
}

CodePudding user response:

api.coingecko has some limitations. Try this

function getStatusCode(url = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=eur&ids=bitcoin'){
   var options = {
     'muteHttpExceptions': true,
     'followRedirects': false
   };
   var url_trimmed = url.trim();
   var response = UrlFetchApp.fetch(url_trimmed, options);
   Logger.log (response.getResponseCode());
}

if you get code 429 that means that you have sent too many requests.

CodePudding user response:

Thank you.

Should this replace other code or be added to the script?

  • Related