Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Google App Script throws Unexpected token e in JSON at position 0 but only sometimes

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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());
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!