I am building an SPFx app and I need to read the rooms and their events from Outlook, our company has 25 conference rooms that can be used to book events in a SharePoint calendar, we need to make sure the room is available in outlook and also be able create the event in outlook when submitted in the SharePoint form
I was able to get the list of all the rooms using the SharePoint context and querying the Microsoft Graph API like this:
const [outlookRooms, setOutlookRooms] = useState<any[]>([]);
React.useEffect(() =>{
const context = props.context;
context.msGraphClientFactory
.getClient('3')
.then((client: MSGraphClientV3): void => {
client
.api('/places/microsoft.graph.room')
.get((response: any, error: any) => {
console.log(response);
console.log(error);
setOutlookRooms(response);
});
});
},[]);
that part is working fine but when I try to get the room events I am getting a 404, this is my code for getting the room events:
const [roomEvents, setRoomEvents] = useState<any[]>([]);
React.useEffect(() =>{
const context = props.context;
context.msGraphClientFactory
.getClient('3')
.then((client: MSGraphClientV3): void => {
client
.api('/groups/roomid/calendarView?startDateTime=2024-01-01T19:00:00-08:00&endDateTime=2024-06-01T19:00:00.00-08:00')
.get((response: any) => {
setRoomEvents(response.value);
console.log(response);
})
;
});
},[]);
2
Answers
I couldn't find a way to get the events for rooms directly from the SPFX, what I end up doing was to create an Azure Function to get the events from Outlook, then I can call the azure function from the SPFX app, you have to enable CORS in the azure function to accept SharePoint calls, the azure function looks like this:
I would use
emailAddress
instead of room id and callusers
endpoint