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

89
Views
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
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!