Request to external api to get authentication token in google appscript

人盡茶涼 提交于 2019-12-25 01:34:35

问题


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);

回答1:


This is the correct code for above code.I got the authentication token by this code.

function getToken(){
  var params ={
    'username': 'xxxxx',
    'rememberMe': true,
    'password':'xxxxx'
  };  
  var headers = {'contentType':'application/json','method':'post','payload':JSON.stringify(params)};
  var url = 'https://demo.overconline.com/api/authenticate';
  var response = UrlFetchApp.fetch(url,headers);
  var result = JSON.parse(response.getContentText());
  Logger.log(result);
}


来源:https://stackoverflow.com/questions/51702190/request-to-external-api-to-get-authentication-token-in-google-appscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!