0
votes

Please anyone can help with the GetUserAvailability method within ews-javascript-api. I am currently developing a roombooking system using this exchange api, but I encounter a problem that I can't find the solution for. Kindly need your help guys

const room = '[email protected]' 
const user = '[email protected]' 
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("[email protected]");
var result = new exch.GetUserAvailability(attendee, tw, ews.AvailabilityData.FreeBusyAndSuggestions);

console.log(result);

and then I got this error :

../ews-javascript-api/js/Core/EwsUtilities.js:567 throw new ArgumentException_1.ArgumentException(Strings_1.Strings.CollectionIsEmpty, paramName); ^ Exception: The collection is empty.at Function.EwsUtilities.ValidateParamCollection (/Users/rsatriaj/node_modules/ews-javascript-api/js/Core/EwsUtilities.js:567:19) at new ExchangeService.GetUserAvailability (/Users/rsatriaj/node_modules/ews-javascript-api/js/Core/ExchangeService.js:1402:37) at Object. (/Users/rsatriaj/booking.js:46:14) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3

As of now, I am not sure what to do. Can you guys help me with this one? Any information would be helpful! Really appreciate it

1

1 Answers

0
votes

GetUserAvailability is not class, it is a method in ExchangeService class. it also expects array of attendee and not just one, this returns a promise and not a synchronous code like in c# version. you can use .then with or without .catch

you may also use it with async await in latest node.

when inside async function
var result = await exch.GetUserAvailability([attendee], tw, ews.AvailabilityData.FreeBusyAndSuggestions);

when using promise
exch.GetUserAvailability([attendee], tw, ews.AvailabilityData.FreeBusyAndSuggestions).then(function(result){/* do something with result*/}, function(error){/* do something when error occur*/})