none
Getting the free time of the meeting attendees by using EWS API RRS feed

  • Question

  • Hi,

    I am newbie to EWS API. I got some problem with getting the free time of the meeting attendees in a given range of time using EWS API (the method is GetUserAvailability).

    According to The MSDN Document,

    the GetUserAvailability method should return free type CalendarEvent like this:

    <FreeBusyView> <FreeBusyViewType xmlns="http://schemas.microsoft.com/exchange/services/2006/types">FreeBusy</FreeBusyViewType> <CalendarEventArray xmlns="http://schemas.microsoft.com/exchange/services/2006/types"> <CalendarEvent> <StartTime>2014-02-12T00:00:00</StartTime> <EndTime>2014-02-13T00:00:00</EndTime> <BusyType>Free</BusyType>

    ^^^^^^^^^^^^^^^^^^^^^^^^

     

    </CalendarEvent>

    The MSDN document:  htts://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-get-free-busy-information-by-using-ews-in-exchange

    My problem is that:

    If there are no events in the calendar of the attendee, the GetUserAvailability method will return empty CalendarEvents.

    Like this picture show 

    https://imgur.com/dIfj0hN

    I can not get any free type CalendarEvents although the attendee's calendar shows that he has free time all day.

    The exchange mail server version is Exchange Server 2016.

    How can I get the meeting attendee's free time in certain time range by using EWS API wrapper(Microsoft.Exchange.WebServices, 15.0.0.0 ,v2.0.50727)?

    The following is the test code  (using outlook.com)

    using Microsoft.Exchange.WebServices.Data;
    using NLog;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp5
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private Logger _logger { get { return LogManager.GetCurrentClassLogger(); } }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string account = "******** @hotmail.com";
                string password = "mypassword";
                ExchangeService service = new ExchangeService();
                service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(account, password);
                service.Url = new Uri("https://outlook.live.com/EWS/Exchange.asmx");
                GetUserFreeBusy(service);
            }
    
            private void GetUserFreeBusy(ExchangeService service)
            {
                string attendee = "******** @hotmail.com";
                List<AttendeeInfo> attendees = new List<AttendeeInfo>();
    
                attendees.Add(new AttendeeInfo()
                {
                    SmtpAddress = attendee,
                    AttendeeType = MeetingAttendeeType.Organizer
                });
    
                AvailabilityOptions availabilityOptions = new AvailabilityOptions();
                availabilityOptions.MeetingDuration = 30;
                availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
    
                GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
                                                                                      new TimeWindow(DateTime.Now.AddDays(-20), DateTime.Now.AddDays(1)),
                                                                                         AvailabilityData.FreeBusy,
                                                                                         availabilityOptions);
    
    
                foreach (AttendeeAvailability availability in freeBusyResults.AttendeesAvailability)
                {
                    _logger.Error("AttendeesAvailability.CalendarEvents count " + availability.CalendarEvents.Count);
                    foreach (CalendarEvent calendarItem in availability.CalendarEvents)
                    {
                        _logger.Error("Free/busy status: " + calendarItem.FreeBusyStatus);
                        _logger.Error("Start time: " + calendarItem.StartTime.ToString("yyyyMMdd HHmmss"));
                        _logger.Error("End time:  " + calendarItem.EndTime.ToString("yyyyMMdd HHmmss"));
    
                    }
                }
            }
        }
    }

    Please help me , Thanks!



                                   

    • Edited by PC_Ryan Friday, March 22, 2019 3:51 AM error correct
    Friday, March 22, 2019 3:48 AM

Answers

  • >> The GetUserAvailability should return the calendar free Events.

    Sorry your miss reading the documentation free events are only returned for Meeting suggestion data its not meant to be used for regular FreeBusy lookups, if you want FreeBusy information that same as what is shown in Outlook or OWA then you need to use MergedFreeBusyStatus. To get the Extra information on Busy slots where you have reviewer status then this is where you can use the CalendarEvents which will be returned for actual events.

    >>But the slot information(free/busy) is really hard to reuse

    Its structured data so once you get you head around that its not that hard to use (yes its a logic problem to solve) eg its just an array of information returned (in the same way it was requested with the slots relative to times windows and time parameter suggested).  Here are some links that may help 

    https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxwavls/cdeb269b-5dc0-4ce0-b85b-08fd3189b366

    >>Is this GetUserAvailability method only support for Exchange 2013 ,Exanage 2010 or Exange 2007?

    Yes but Meeting suggestions where a feature that was introduced in later version of Exchange but MergedFreeBusyStatus will work on any version of Exchange and is what is used by Outlook/OWA.


    • Edited by Glen ScalesMVP Friday, March 29, 2019 5:22 AM
    • Marked as answer by PC_Ryan Friday, March 29, 2019 6:36 AM
    Friday, March 29, 2019 5:21 AM

All replies

  • In the example you have show this is suggested meeting data that is being returned in the calendar events which only gets returned when you include a Time windows for suggestion. Your code is just making a conventional Freebusy request which means you will only get Busy events in the response. You need something like

        // Specify options to request free/busy information and suggested meeting times.
        AvailabilityOptions availabilityOptions = new AvailabilityOptions(); 
        availabilityOptions.GoodSuggestionThreshold = 49; 
        availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
        availabilityOptions.MaximumSuggestionsPerDay = 2;
        // Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
        availabilityOptions.MeetingDuration = 60; 
        availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good; 
        availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
        availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

    Where the DetailedSuggestionsWindow reflects that window where you want such Free Events returned.

    Cheers
    Glen

    Monday, March 25, 2019 10:44 PM
  • Hi Glen,

    Thanks for your reply.

    I tried the code you post but still got empty calendar event.

    the result picture: 

    https://imgur.com/a/LBVe4LS

    the following is the code:

    // Specify availability options
                AvailabilityOptions availabilityOptions = new AvailabilityOptions();
                availabilityOptions.GoodSuggestionThreshold = 49;
                availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
                availabilityOptions.MaximumSuggestionsPerDay = 2;
                // Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
                availabilityOptions.MeetingDuration = 60;
                availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
                availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
                availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
    
    
    
    
    
    
    
                
                // Return a set of of free/busy times
                GetUserAvailabilityResults freeBusyResults = service.GetUserAvailability(attendees,
                                                                                    new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2)),
                                                                                         AvailabilityData.FreeBusy,
                                                                                         availabilityOptions);

    I tried to use the GetUserAvailability with the parameter AvailabilityData.FreeBusyAndSuggestions, too.

    But the calendar event is empty too.

    Did I miss something else?

    Please help me, thanks!

    Tuesday, March 26, 2019 2:40 AM
  • In your example you only have one user your trying to get Meeting suggestion time for ? if your just trying to get the Freebusy information then that's not the correct way to go about it. What you should be doing is just getting the raw freebusy information eg FreeBusyViewType.DetailedMerged and then access the slot information from MergedFreeBusyStatus. The suggestion data mean you have two or more users you comparing against and its return freeslot based on those attendees in the Meeting.

    Cheers
    Glen

    Wednesday, March 27, 2019 5:18 AM
  • Hi Glen,

    Thanks for your reply.

    1.
    In my example, it just a test code so I only use one email. In fact, I need to get the free/busy of  multi users in one EWS API Call.

    I don't need any meeting suggestion data returned by the GetUserAvailability method. 

    I tried the GetUserAvailability with the parameter AvailabilityData.FreeBusyAndSuggestions just because I can not get any free Event

    with the other parameter(AvailabilityData.FreeBusy,AvailabilityData.Detail...,etc)


    2.

    I tried the FreeBusyViewType.DetailedMerged and accessed the slot information from MergedFreeBusyStatus.

    The result picture:

    https://imgur.com/a/AmtCx8X

    But the slot information(free/busy) is really hard to reuse

    Is the slot information only way to get free/busy?

    According to the document 

    https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-get-free-busy-information-by-using-ews-in-exchange

    The GetUserAvailability should return the calendar free Events.

    But no matter how hard I tried(on exchange 2016 and outlook.com), the GetUserAvailability  method never return the Free Event(only busy event).

    Is this GetUserAvailability method only support for Exchange 2013 ,Exanage 2010 or Exange 2007?


    Please help me, thanks!
    Thursday, March 28, 2019 4:59 AM
  • >> The GetUserAvailability should return the calendar free Events.

    Sorry your miss reading the documentation free events are only returned for Meeting suggestion data its not meant to be used for regular FreeBusy lookups, if you want FreeBusy information that same as what is shown in Outlook or OWA then you need to use MergedFreeBusyStatus. To get the Extra information on Busy slots where you have reviewer status then this is where you can use the CalendarEvents which will be returned for actual events.

    >>But the slot information(free/busy) is really hard to reuse

    Its structured data so once you get you head around that its not that hard to use (yes its a logic problem to solve) eg its just an array of information returned (in the same way it was requested with the slots relative to times windows and time parameter suggested).  Here are some links that may help 

    https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxwavls/cdeb269b-5dc0-4ce0-b85b-08fd3189b366

    >>Is this GetUserAvailability method only support for Exchange 2013 ,Exanage 2010 or Exange 2007?

    Yes but Meeting suggestions where a feature that was introduced in later version of Exchange but MergedFreeBusyStatus will work on any version of Exchange and is what is used by Outlook/OWA.


    • Edited by Glen ScalesMVP Friday, March 29, 2019 5:22 AM
    • Marked as answer by PC_Ryan Friday, March 29, 2019 6:36 AM
    Friday, March 29, 2019 5:21 AM
  • Hi Glen,
    Thanks for your reply.

    These information really help me a lot.  I will read the documents in the link.

    Thanks!!!

    Friday, March 29, 2019 6:36 AM