在应用程序中发布对外部API的请求

时间:2018-09-12 10:52:45

标签: javascript google-apps-script gmail-addons

我尝试将发布请求发送到外部服务器。但是我总是遇到500错误。我在Postman中使用此URL和JSON对象进行了测试,并且可以正常工作。

  

https://demo.overconline.com/api/opportunities的请求失败,返回了代码500。服务器响应被截断:{“ message”:“ error.internalServerError”,“ description”:“内部服务器错误”,“ fieldErrors”:null}(使用MutetHttpExceptions选项检查完整的响应)(第178行,文件“代码”)

function createdOpportunity(){  
  var auth = getToken(); 
  var data = {
  "createdBy": "first-admin",
  "sequenceNumber": "",
  "indexKeyValue": "opportunity name",
  "stageId": "5b680dbcb5557900013686b8",
  "assignee": "None",
  "stageHistory": [
    {
      "stageId": "5b680dbcb5557900013686b8",
      "stageHistoryRecords": [
        {
          "addedDate": null,
          "removedDate": ""
        }
      ]
    }
  ],
  "order": [],
  "permissionType": 2
};

  Logger.log(data);
  Logger.log(JSON.stringify(data));
  var webAppUrl="https://demo.overconline.com/api/opportunities";
  var header = {'contentType':'application/json','Authorization': 'Bearer '+ auth };
  var options = { 'method':'POST','headers':header ,'payload':JSON.stringify(data)};
  var response = UrlFetchApp.fetch(webAppUrl, options);
  var result = JSON.parse(response.getContentText());
  Logger.log(result);
  Logger.log('Permission type  '+response);
  return result;
}

0 个答案:

没有答案