I need to access the raw body of a post request in Google App Script. I see there is something like
function doPost(request) {
request.contentLength
}
that actually returns the right length of the raw content of the request body. So I thought there must be something to get the complete body, e.g. as a String.
I am not looking to access form field parameters that might be transferred using post.
I know this question is old, but a lot of things have changed and Google has made this available now. You can easily access the body of a POST request from doPost(e)
using:
e.postData.contents
If you want to parse incoming JSON, use this:
JSON.parse(e.postData.contents)
From the Release Notes of May 9, 2013, use request.postData.getDataAsString():
function doPost(request) {
var jsonString = request.postData.getDataAsString();
var jsonData = JSON.parse(jsonString);
sheet.appendRow([ 'Data1:' , jsonData.Data1 ]); // Just an example
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With