Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
How to POST JSON to a Google Apps Script with DEV Link

I have a Google Apps Script Project which I need to receive some request via GET and POST methods. Every goes fine with GET method because I can simulate it via URL in the browser; the problem is in the POST method, I can't do it via CURL it shows a Google permissions error.

Heres my code

function doPost(e) {

  let response = ContentService.createTextOutput()
  response.setContent(JSON.stringify({
    response: e
  }))
  response.setMimeType(ContentService.MimeType.JSON)

  return response
}

function foo()
{
    var url = "https://script.google.com/macros/s/id/dev";
    var headers = {"Authorization": "Bearer " + ScriptApp.getOAuthToken()};
    var payload = {
      debug: 'data ok'
    }

    var params =
    {
        "method": "post",
        "contentType": "application/json",
        "headers": headers,
        "payload": JSON.stringify(payload),
        "muteHttpExceptions": true
    };
    var response = UrlFetchApp.fetch(url, params).getResponseCode()
    Logger.log(response);
}

I need to debug with a https://script.google.com/macros/s/id/**dev** link. The purpose is not generate a version with each test.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I believe your goal is as follows.

  • You want to request to your Web Apps with https://script.google.com/macros/s/###/dev using a curl command.

In this case, how about the following curl command?

Sample curl command:

When your payload is used, it becomes as follows.

curl -L \
  -d '{"debug": "data ok"}' \
  -H "Authorization: Bearer ###your access token###" \
  -H "Content-Type: application/json" \
"https://script.google.com/macros/s/###/dev"
  • In order to access to https://script.google.com/macros/s/###/dev, it is required to include the access token in the request header. And as a scope, it is required to use for Drive API. For example, it's https://www.googleapis.com/auth/drive.readonly.

  • If you want to test this, you can retrieve the access token using the following sample script of Google Apps Script. You can use this access token with the above curl command.

      function getAccesstoken() {
        console.log(ScriptApp.getOAuthToken())
        // DriveApp.getFiles(); // This is used for automatically detecting the scope of `https://www.googleapis.com/auth/drive.readonly`.
      }
    
  • In this case, e of doPost(e) is as follows.

      {"contextPath":"","parameter":{},"postData":{"contents":"{\"debug\": \"data ok\"}","length":20,"name":"postData","type":"application/json"},"contentLength":20,"queryString":"","parameters":{}}
    

Reference:

  • Taking advantage of Web Apps with Google Apps Script
about 4 years ago · Juan Pablo Isaza Report

0

In the current state, Test Deployments are only accessible for users who have edit access to the script. This means that you need to be logged in to access this deployment, and you cannot do it through a cURL request unless you have the necessary cookies to do it.

As a workaround follow these steps:

  1. Open Google Developer Tools > Network Tab.
  2. Go to the page where you have the Test Deployment, /dev/ endpoint.
  3. In the request named dev, click the second button and go to Copy > Copy as cURL. This will copy the request with all the necessary cookies.
  4. In a terminal, make the request by adding -X POST.

The response includes the HTML of the desired page.

Documentation
  • Google Cookies
  • Replay a network request in cURL
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!