EN
Google Sheets / Apps Script - handle GET requests
0
points
This article will show you how to handle GET requests in Google Sheets (Apps Script).
You can use Google Apps Script like a web app - below we show you how to get a response after a GET request.
Practical example
1. Create doGet()
function
GET requests are handled by the doGet()
function. In the example below, when Apps Script gets a GET request, it will respond with a JSON object:
[{"message":"hello"}]
Steps
- Go to Tools -> Script editor.
- Paste this code:
function doGet() {
var response = [{ message: 'hello'}]; // your response
return ContentService
.createTextOutput(JSON.stringify(response))
.setMimeType(ContentService.MimeType.JSON)
}
2. Deploy a script as a web app
Steps
- Go to Deploy -> New deployment.
- From the select type list, select Web app.
- Fill in the name details and specify who has access to the deployment.
- After clicking Deploy you will get a deployment URL to which you can send GET requests.