doPost problem

Hi, I am trying to call a webhook in a bot. in a step to configure the call, I used JSON, verb as ‘Post’ But the web app with doPost(e), return a wrong message:"Webhook HTTP post request failed with exception The remote server returned an error: (401) Unauthorized. ". Can any one help me to figure out why?


You need to authorize the app script app. Run a dummy function (add it to in the app script editor and then authorize it.

1 Like

I checked the webapp and it already authorized to “every one” to use. I run the test of the bot and the auditor from monitoring shows the post to webapp is successful however, Webapp’s executive log shows doPost failed and I am pretty sure that doPost never runs as I have Logger set up immediate after it is called, no log message ever found. I guess something wrong with the appsheet header information(default)? The JSON format is ok and I debugged the backend function(called by doPost to add a row in a table), it works. so the doPost is the problem

I run a few experiment and found out that the problem is actually caused the URL. I used test deployment url(/dev). The problem disappeared if switched to deployment url(ended with /exec), which is not a problem when I use doGet. so probably doPost has more security check?

New issue: fail to get the contents from doPost event body. The code snippet is as following:function doPost(e){
var data = JSON.parse(e.postData.contents);
var id = data[“ID”];
var emmailText = data[“Email”];
var email = emailText.split(" , ");

return ContentService.createTextOutput(JSON.stringify(e))
help to check it to see if it is the right way to get the data in the Post request. thx Tim

Check the JSON template and make sure it is valid JSON. You must use double quotes rather than single quotes for strings.

1 Like

I am using double quotes. anyway, why Post request using url ended with “/dev” will have the webapp decline the request as unauthorized(401) while using “/exec” instead will go through fine?