I'm using a third-party API and my POST request works as expected when I send from the API documentation "test" page in my browser, or from the Postman Windows native app.
I get error codes when I send the same request from Google Apps Script. I am able to send/receive GET requests using GAS and I can also send/receive POST requests using GAS to other APIs.
This GAS GET request works correctly:
var options = {
"headers" : {
"Authorization" : "Bearer " + accessToken,
"Accept": "application/json"
}
};
var response = UrlFetchApp.fetch(url, options);
Headers:
Accept: application/json
Accept-Encoding: gzip
Accept-Language: en-US
Authorization: Bearer {token}
Content-Length: 638
Content-Type: application/json
DNT: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML
X-Forwarded-For: xxx.xxx.xxx.xx
X-Forwarded-Port: 443
X-Forwarded-Proto: https
This GAS POST request produces errors:
var options = {
"headers" : {
"Authorization" : "Bearer " + accessToken,
"Accept": "application/json",
"Content-Type": "application/json",
"Accept-Language": "en-US"
},
"method" : "post",
"payload" : JSON.stringify(this_payload)
};
var response = UrlFetchApp.fetch(url, options);
The GAS POST request sends these headers:
Accept: application/json
Accept-Encoding: gzip,deflate,br
Accept-Language: en-US
Authorization: Bearer {token}
Connection: close
Content-Length: 387
Content-Type: application/json
User-Agent: Mozilla/5.0 (compatible; Google-Apps-Script)
This GAS POST request gives the error:
Response Code 500
code: infrastructure.common.SystemException
description:"System error, please re-try"
Is it possible that the API is simply not accepting connections from GAS? The User-Agent lists Google-Apps-Script. Or is it more likely that I have some parameter wrong? I am able to get the parameters correct via two other platforms, so I think parameters are correct.