Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda