EWS-javascript-api可用性问题

时间:2018-06-20 06:00:05

标签: javascript node.js exchangewebservices ews-javascript-api

请任何人都可以在ews-javascript-api中使用GetUserAvailability方法进行帮助。 我目前正在使用此交换API开发客房预订系统,但是遇到无法解决的问题。请帮助您

const room = 'roomemail@email.com' 
const user = 'email@email.com' 
var myPwd = 'password'

// Dependencies
var ews = require("ews-javascript-api");

// Debug Mode
ews.EwsLogging.DebugLogEnabled = false;

// Login to Exchange URI, Username and Password, Version of Exchange
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
exch.Credentials = new ews.ExchangeCredentials(user, myPwd);  
exch.Url = new ews.Uri("https://mail.domain.com");

// Check Availability
var now = new Date();
now.setMinutes(now.getMinutes() + 1);

var startTime = new ews.DateTime(now);
var tw = new ews.TimeWindow(ews.DateTime.Now, ews.DateTime.Now.AddHours(8));
var attendee = new ews.AttendeeInfo("roomemail@email.com");
var result = new exch.GetUserAvailability(attendee, tw, ews.AvailabilityData.FreeBusyAndSuggestions);

console.log(result);

然后出现此错误:

  

../ ews-javascript-api / js / Core / EwsUtilities.js:567抛出新   ArgumentException_1.ArgumentException(Strings_1.Strings.CollectionIsEmpty,   paramName);               ^例外:集合为空。在Function.EwsUtilities.ValidateParamCollection中   (/Users/rsatriaj/node_modules/ews-javascript-api/js/Core/EwsUtilities.js:567:19)       在新的ExchangeService.GetUserAvailability(/Users/rsatriaj/node_modules/ews-javascript-api/js/Core/ExchangeService.js:1402:37)       在对象。 (/Users/rsatriaj/booking.js:46:14)       在Module._compile(module.js:652:30)       在Object.Module._extensions..js(module.js:663:10)       在Module.load(module.js:565:32)       在tryModuleLoad(module.js:505:12)       在Function.Module._load(module.js:497:3)       在Function.Module.runMain(module.js:693:10)       在启动时(bootstrap_node.js:191:16)       在bootstrap_node.js:612:3

截至目前,我不确定该怎么办。你们能帮我这个吗?任何信息都有帮助!真的很感激

1 个答案:

答案 0 :(得分:0)

GetUserAvailability不是类,它是ExchangeService类中的方法。它还需要一组参与者,而不仅仅是一个参与者,这将返回一个Promise,而不是像c#版本中的同步代码。您可以将.then.catch一起使用

您还可以将其与最新节点中的async await一起使用。

在异步函数中时
var result = await exch.GetUserAvailability([attendee], tw, ews.AvailabilityData.FreeBusyAndSuggestions);

使用诺言时
exch.GetUserAvailability([attendee], tw, ews.AvailabilityData.FreeBusyAndSuggestions).then(function(result){/* do something with result*/}, function(error){/* do something when error occur*/})