【发布时间】:2016-12-07 05:06:39
【问题描述】:
我尝试使用 UrlFetchApp 从 API 获取信息。我在 POSTMAN 中尝试了 GET 和 POST 命令,它工作正常。在 Google Apps 脚本中,第一个有效,第二个返回错误 404。
function pru_demo() {
// Log In.
var options = {
'method' : 'POST',
'contentType': 'application/json'
};
var response=UrlFetchApp.fetch('https://demo.erpnext.com/api/method/login?usr=demo@erpnext.com&pwd=demo', options);
var data=JSON.parse(response)
Logger.log(data.full_name);
// Get Employes
options = {
// 'muteHttpExceptions' : true,
'method' : 'GET',
'contentType': 'application/json'
};
response=UrlFetchApp.fetch('https://demo.erpnext.com/api/resource/Employee', options);
Logger.log(response.getContentText());
}
【问题讨论】: