I'm trying to send a post request to my node js server through google app script, but the received data is {}.
I tried sending a Post through zapier and postman, zapier will work if I set the payload type to "form" and postman will work if I set the body as x-www-form-urlencoded.
Any idea to make it work on google app script ?
Have you loaded json and urlencoded in your node server?
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
In your script, how about the following modification?
var requestOptions = {
"method" : "post",
"contentType" : "application/x-www-form-urlencoded",
"body" : payload
//"body" : payload,
}
var requestOptions = {
"method": "post",
"payload": payload
};
body is not existing in UrlFetchApp.application/x-www-form-urlencoded is the default content type.payload is requested as the form data.As the additional information, in your server-side of Node.js, if app.use(bodyParser.json()); is used, it is required to request as application/json as follows. Please be careful about this.
var requestOptions = {
"method": "post",
"payload": JSON.stringify(payload),
"contentType": "application/json"
};