Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda