Makeinfo Blog

Makeinfo Blog

Google Script GET Request

Google Script GET Request

Subscribe to my newsletter and never miss my upcoming articles

Believe it or not, taking a few minutes to learn how to do GET requests using Google App script can actually help you save tons of time. Always make sure about the Google Script Quotas.

If you've never heard of Google App Script, or you've tried it but didn't get far, don't worry, this is a beginner-friendly tutorial to do GET requests from Google Script Editor. Check my previous post about Google Clasp to create Google App Script.

In this post, I will show you how to do GET requests using Google App Script on your Google Sheet. GS is the file format used to save a Google App Script.

From the code, Urlfetch is the function we're using to do the GET request.

How to handle GET request from Google Script in 3 Easy Steps

  1. Sign in to your Google Account. Then, open Google Script or Google Sheet -> Script Editor.

  2. Create a new project and start the code editor. You can see that Code.gs is already opened on the window. You can copy and paste the source code below into the editor.

  3. Source Code

var url = 'YOUR URL HERE';

function mainFunction() {
  getRequest(param);
}

function getRequest(param) {
  var response = UrlFetchApp.fetch(url);
  //Logger.log(response.getContentText());
  if (response.getResponseCode() == 200) {

    var params = JSON.parse(response.getContentText());

    Logger.log(params);
     return params;
  } else {

   Logger.log("Error from getUid()")
   return "error"
  }
}

Add appropriate URL to check this function. Finally, you can execute the Google Script main function from the dropdown (select mainFunction() in our case).

Now, I believe that you get to know how to handle a GET request from Google Script. If you like to notify latest productivity tips using Google Workspace, please don't hesitate to subscribe to our newsletter.

Join our Mailing List

 
Share this