K
K
kyprijan2019-04-24 17:52:02
Google Apps Script
kyprijan, 2019-04-24 17:52:02

How to activate doGet(e) using UrlFetchApp?

How to use UrlFetchApp request to activate doGet(e) function in another google script?
I posted the script itself as a web application with the parameter "Who has access to the application: everyone, including anonymous users"
And if you just run it in the browser (and through incognito), then it works, but it doesn't.
The request itself.

var payload = {
        "name" : "name",
      };
      var options = {
        "method" : "GET",
        "payload" : payload,
        "followRedirects" : true,
        "muteHttpExceptions": true
      };
      var url="https://script.google.com/macros/s/(id скрипта)/exec";
      var resp=UrlFetchApp.fetch(url,options).getContentText();

Conditional function doGet(e).
function doGet(e) {

  var Name = e.parameter.name;
  return ContentService.createTextOutput(Name);
  }

Here is what .getContentText();
<!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Error</title><style type="text/css">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style="margin:20px"><div><img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png"></div><div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">Script function not found: doPost</div></body></html>

This is what UrlFetchApp.getRequest(url, options) outputs
{headers={X-Forwarded-For=187.121.239.122}, method=post, payload=name=name, followRedirects=true, validateHttpsCertificates=true, useIntranet=false, contentType=application/x-www-form-urlencoded, url=https://script.google.com/macros/s/AKfycbzSESoSAmLBYdA8MdiqSdcVJNCVB3dhg3vFSrQBNM7ydetz0So/exec}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2019-09-08
@oshliaer

They wrote to you:
This is probably because you are not sending a request GET, but POSTa request. At a minimum GET, it has no bodypayload and does not need it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question