clhager
clhager

Reputation: 3

doGet() and doPost() requests with a Google Web Script

I'm trying to send information to a Google Web Script (specifically, send a JSON object containing info to write to a Google Sheet) but I'm having trouble sending GET and POST requests to my Google Script.

I'm using Node.js and the "request" module to send the requests, but I don't receive what my doGet() and doPost() functions are supposed to return, instead I receive very long HTML files that are unrelated, some of which indicate a 404 error.

As an example:

Node.js

var request = require('request');
request("https://script.google.com/macros/s/my-web-script/exec", function (error, response, body) {
    console.log(body);
});

Google Web Script:

function doGet(){
    textOutput = ContentService.createTextOutput("Hello World! Welcome to the 
                 web app.")
    return textOutput
}

I published the web script and made it accessible to anyone. I'm not sure why this isn't working.

Upvotes: 0

Views: 11849

Answers (1)

Tanaike
Tanaike

Reputation: 201388

I think that both your scripts work fine. So can you confirm the situation of deployed Web Apps, again? When you modify your script, Web Apps has to be redeployed as a new version.

How to deploy Web Apps is as follows.

  • On the Script Editor
  • Publish
    • Deploy as Web App
      • Create new Project version
      • At Execute the app as, select "your account"
      • At Who has access to the app, select "Anyone, even anonymous"
      • Click "Deploy"
      • Copy "Current web app URL"
      • Click "OK"

The Current web app URL is https://script.google.com/macros/s/my-web-script/exec in your script.

The detail information is here.

If I misunderstand your question, I'm sorry.

Upvotes: 1

Related Questions