Skip to content

Instantly share code, notes, and snippets.

@gautamsi
Last active June 3, 2023 01:44
Show Gist options
  • Save gautamsi/ba0561da1b4a2b29478943ba5f002328 to your computer and use it in GitHub Desktop.
Save gautamsi/ba0561da1b4a2b29478943ba5f002328 to your computer and use it in GitHub Desktop.
Fetch Appointments using ews-javascript-api
import { ExchangeService, ExchangeVersion, WebCredentials, Uri, DateTime, CalendarView, WellKnownFolderName, EwsLogging } from "ews-javascript-api";
import credentials = require("./credentials"); //for username and password
EwsLogging.DebugLogEnabled = false;
var service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials(credentials.userName, credentials.password);
service.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx");
var view = new CalendarView(DateTime.Now.Add(-1, "week"), DateTime.Now); // appointments in last one week.
service.FindAppointments(WellKnownFolderName.Calendar, view).then((response) => {
let appointments = response.Items;
let appointment = appointments[0];
console.log("Subject: " + appointment.Subject);
console.log("Start Time: " + appointment.Start);
console.log("End Time: " + appointment.End);
console.log("Recipients: ");
appointment.RequiredAttendees.Items.forEach((a) => {
console.log(a.Address);
});
console.log("unique id: " + appointment.Id.UniqueId, true, true);
}, function (error) {
console.log(error)
})
@Lakshmiganthangithub
Copy link

Lakshmiganthangithub commented Sep 19, 2022

Hello @gautamsi
Is this code used to fetch the appointments of all the users listed in the Calendar folder of the outlook?

@gautamsi
Copy link
Author

this is only for one user calendar

@polpenyarrojaNik
Copy link

When I try to connect with service I use a @domain.com but set credentials get an unauthorized error but if I use a @outlook.com I can connect successfully.

Can you help me?
service.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx"); service.Credentials = new WebCredentials(xxxx@domain.com, credentials.password);

@gautamsi
Copy link
Author

gautamsi commented Jun 3, 2023

you can not do Basic Auth with this anymore, you need to get OAuth credential working to use O365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment