- Docs: Click here
- (TODO) Features & Limitations of Google Apps Script | Docs: Click here
- (TODO) Libraries | Docs: Click here
Interesting StackOverflow Questions:
❤️ ❤️ ❤️ For more recent test codes using Apps Script you can search for #Apps Script
in my Office Utility Tools Notes google doc.
Important Points to Remember:
- You can create google apps script project here - https://script.google.com/home/start
- You can only have two function i.e,
doGet
anddoPost
function for GET and POST requests to be handled on the web url respectively.- Any deployment's
doGet
funciton is only callable if you are loggedin otherwise you would be prompted to login in the browser.
- Any deployment's
- Note: If you are getting CORS error when you call the deployment url of the file, then it means you have not defined the function name
doPost
in your file which is the actual function that is called when any the web api call is made. - You do need to deploy each versioned deployment to be able to test it.
- Using postman to make call to your deployment url:

Official Docs: Click here
We can make use "Test Deployment" and adding appropriate query in the end.
Using test deployments are really fun because we do not need to deploye after each save, i.e, on each save the function is lively updated.
For e.g., "username=sahil" and then trying to open below url in
Browser url bar directly and it would show the params in the browser itself
https://script.google.com/macros/s/AKfycbwv0Vvlmg6Vhd37gFROw9efDDFQixCShKh0Wt4XE48/dev?username=sahil
OUTPUT:

Refer here: Click here
function doGet(e) {
var params = JSON.stringify(e);
MailApp.sendEmail({
to: "sahilrajput03@gmail.com",
subject: "Call Sucessful",
htmlBody: "I am your <br>" +
"DATA"
});
return ContentService.createTextOutput(params).setMimeType(ContentService.MimeType.JSON);
}
Note: When you try to send email via your script you might encouter this error, so you might need to handle this (TODO_SAHIL).

Article: Click here
// file1.gs
function doGet() {
return ContentService.createTextOutput('Hello, function1.');
}
// file2.gs
function doGet() {
return ContentService.createTextOutput('Hello, function2.');
}
function doGet() {
return ContentService.createTextOutput('Hello, function3.');
}
Now, when you hit the test deployment (or versioned deployment) url, you would see Hello, function3.
. This means that the bottom most file and the bottom most function inside that file overwrites any other doGet
function in that file and other doGet
functions in any other files.
Also, you can change the order of the files in google apps script project by clicking the tripple dot menu option and then choosing the Move file up
or Move file down
option respectively.
// File: file2.gs (my bottom most file in the google apps script project)
// NOTE: `myFun` can be declared:
// 1. above or below the `doGet` function
// 2. in any different .gs file irrespective of that file being above or below in the sequence order of the project files
function myFun() {
return "myFun is cool!"
}
function doGet() {
const message = myFun()
return ContentService.createTextOutput(message);
}
Now, when you hit the test deployment (or versioned deployment) url, you would see myFun is cool!
.