Search code examples
c#node.jsexchangewebservicesoffice365api

Get room meetings on Office365 using Node JS - REST API


I want the get all meetings in rooms. I'm using the following code but I want use Node JS. So can I do this operation ? if yes how ? I can't any information about this issue. All samples and code structures are used to get my own meetings. Thanks a lot.

public void get_rooms()
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
            service.Credentials = new WebCredentials("user@example.com", "password");
            service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "ROOM_1@example.com");

            DateTime startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 8, 0, 0);
            DateTime endDate = startDate.AddHours(12);
            CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
            CalendarView cView = new CalendarView(startDate, endDate);
            cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start,
                AppointmentSchema.End, AppointmentSchema.Organizer,
                AppointmentSchema.AppointmentState, AppointmentSchema.Id);
            List<string> MailAddress = new List<string>();
            FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
            foreach (Appointment appointment_result in appointments)
            {
                Appointment appointmentDetailed = Appointment.Bind(service, appointment_result.Id,
                    new PropertySet(BasePropertySet.FirstClassProperties)
                    {
                        RequestedBodyType = BodyType.Text
                    });

                foreach (Attendee attendee in appointmentDetailed.RequiredAttendees)
                {
                    listBox1.Items.Add("Attendee Mail: " + attendee.Address.ToString());
                }
                listBox1.Items.Add("Organizer: "appointment_result.Organizer.Name);
            }
        }

Solution

  • Your question is a little too broad there is a javascript version of the EWS Managed API (the code you posted above) https://github.com/gautamsi/ews-javascript-api this should work okay in Node Js. You could also do the same thing using the Graph API (REST) which there are samples for https://github.com/microsoftgraph/nodejs-connect-rest-sample. These are where I would suggest you start.

    On the EWS code you posted this is using Impersonation for accessing a Room Mailbox rather then impersonation you should just be able to use delegation eg

    FolderId RoomMailboxFolderId = new FolderId(WellKnownFolderName.Calendar,"Room@domain.com");
    CalendarFolder calendar = CalendarFolder.Bind(service, RoomMailboxFolderId, new PropertySet());
    

    You then don't need to keep changing the account your impersonating the access other Room Calendars.