K
K
Kaunov_ivan2015-10-07 17:21:26
Google Workspace
Kaunov_ivan, 2015-10-07 17:21:26

How to make Google apps script work remotely?

There is a script - it receives a bunch of data and forms letters from them and sends them out. It was created as a separate project.
Google has a function to use scripts via a POST request - I try to apply - it writes an error - what am I doing wrong? I check the
link to the script through the Directory . It gives a 404 error.

404 OK
- HIDE HEADERS -
cache-control:  private
content-encoding:  gzip
content-length:  115
content-type:  application/json; charset=UTF-8
date:  Fri, 09 Oct 2015 07:23:05 GMT
server:  ESF
vary:  Origin, X-Origin, Referer
{
 "error": {
  "code": 404,
  "message": "Requested entity was not found.",
  "status": "NOT_FOUND"
 }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2015-10-09
@oshliaer

Consider two possible problems:
First. Before sending a request, your application must authorize through and receive a token.

this method requires authorization with an OAuth 2.0 token that includes at least one of the scopes listed in the Authorization section; script projects that do not require authorization cannot be executed through this API.

Second: You have a 404 error. Resource is not found. Check if the address is correct
POST https://script.googleapis.com/v1/scripts/{scriptId}:run

In this case {scriptId}, this is the unique number of the script itself, which is located in the menu File - Project Properties - Project Key
If you do not want to log in, but you really need to send a POST, try
function doPost(e) {
  return ContentService.createTextOutput(JSON.stringify({status: 'ok'}))
    .setMimeType(ContentService.MimeType.JSON);
}

But, then you need to publish the script as a web application and allow execution access for everyone, even anonymous users.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question