Hi,
I have been trying for hours now to build a next.js app that reads events from a shared outlook calendar.
For some reason I cannot explain I always receive:
GraphError
at GraphErrorHandler.eval (webpack-internal:///(action-browser)/./node_modules/@microsoft/microsoft-graph-client/lib/es/src/GraphErrorHandler.js:87:26)
at Generator.next (<anonymous>)
at eval (webpack-internal:///(action-browser)/./node_modules/tslib/tslib.es6.mjs:179:71)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///(action-browser)/./node_modules/tslib/tslib.es6.mjs:161:12)
at GraphErrorHandler.getError (webpack-internal:///(action-browser)/./node_modules/@microsoft/microsoft-graph-client/lib/es/src/GraphErrorHandler.js:80:64)
at GraphRequest.eval (webpack-internal:///(action-browser)/./node_modules/@microsoft/microsoft-graph-client/lib/es/src/GraphRequest.js:291:104)
at Generator.throw (<anonymous>)
at rejected (webpack-internal:///(action-browser)/./node_modules/tslib/tslib.es6.mjs:171:40)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
statusCode: 401,
code: null,
requestId: null,
date: 2024-03-06T15:17:39.447Z,
body: ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
My app registration has the correct permissions:
Calendars.Read |
Application |
Read calendars in all mailboxes |
Calendars.Read |
Application |
Read calendars in all mailboxes |
This is my quick a dirty backend code (I call fetchOutlookEvents() in my frontend):
// Create an instance of the TokenCredential class that is imported
const tokenCredential = new ClientSecretCredential(
"tenantID", // just removed for security reasons
"clientD", // just removed for security reasons
"secret" // just removed for security reasons
);
const authProvider = new TokenCredentialAuthenticationProvider(
tokenCredential,
{ scopes: ["https://graph.microsoft.com/.default"] }
);
const client = Client.initWithMiddleware({
debugLogging: true,
authProvider,
});
export const fetchOutlookEvents = async () => {
try {
const events = await client
.api("/users/84c2fdbe-c42d-455a-a1ec-45115387217f/calendar")
.get();
console.log(events.value);
} catch (error) {
console.log(error);
}
};