I am trying to make a call to external api using google Appscript. But i am gettting always error 500.It would be grateful if anyone can help.
Request failed for https://demo.overconline.com/api/authenticate returned code 500. Truncated server response: {"message":"error.internalServerError","description":"Internal server error","fieldErrors":null} (use muteHttpExceptions option to examine full response) (line 10, file "Code")
function getToken(){
var params ={
"username": "xxxx",
"rememberMe": true,
"password": "xxx",
};
var headers = {'Content-Type':'application/json','method':'post','payload':'params'};
var url = 'https://demo.overconline.com/api/authenticate';
var response = UrlFetchApp.fetch(url,headers);
var result = Utilities.jsonParse(response.getContentText());
var token = result.access_token;
Logger.log(result);
headers
is used asUrlFetchApp.fetch(url,headers)
,'Content-Type':'application/json'
can be modified as'contentType':'application/json'
.params
is not used topayload
as an object, because'params'
is enclosed by the single quotes. From the content type,payload
might beJSON.stringify(params)
. Reference is here. If these modifications were not your solution, can you provide a document for the specification of the API you want to use? – TanaikeUtilities.jsonParse(jsonString)
had already been deprecated . So please useJSON.parse(jsonString)
. – Tanaike