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

88
Vistas
Google Sheet App Script Error With API Calls

I wrote a Google sheet app script that requires some API calls. When I run the script within App Script editor, it runs fine.

But when I call the formula from within Google Sheets, then it throws an error saying "invalid API key" while I know that API is correct.

    const api_key = "";

    const response = UrlFetchApp.fetch("https://serpapi.com/search.json?q=" + keyword 
 +"&hl="+"&gl="+location+"&num=100"+ "&engine = Google" + 
"&google_domain=google.co.uk"+"&api_key="+api_key);

Here is the whole script

    function GetRank(keyword, domain, location) {

  

  

const response = UrlFetchApp.fetch("https://serpapi.com/search.json?q=" + keyword +"&hl="+"&gl="+location+"&num=100"+ "&engine = Google" + "&google_domain=google.co.uk"+"&api_key=xxx-xxx-xxx");

 

  const json = response.getContentText();
  const results = JSON.parse(json);
  const final = results.organic_results;
  for(let i = 0; i< final.length; i++){
   rank = 'Not in Top 100';
   links = final[i].link;
   if(links.includes(domain)){
     rank = final[i].position;
     show = final[i].link;
     break;
     
   }

  }
  console.log(rank, show);
  return [rank, show];

}
about 4 years ago · Santiago Trujillo
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