I have SPFx webpart where i want to create form which have Outlook locations, meeting rooms, there is one service account which should block meeting room and cancel meeting and edit meeting.
Also, I have registered azure app where i will have microsoft graph permissions but i am not sure how to connect it and use it in spfx webpart.

prachi gupta39 reputationPosted Sep 16, 2024, 1:43 AM EDT
Hi Aman,
Thank you for posting reply!
I have two queries regarding the same.
1. In step 2, Regarding APi permissions, do we need to have them in organizational level,??? I have only User. Read.all permissions under api access in organizational level and when i try to use msgraphclientv3 to send permissions it does not get displayed in sharepoint admin center.
2. I want to block meeting room fetch locations on behalf of service account as we can not give permissions to all users to access outlook, how can i use this in spfx. How to connect azure app in spfx, where to add app id, secret?? How to use service account instead of current ligged in user context,???
Thank you in advance!!
prachi gupta39 reputationPosted Sep 16, 2024, 1:56 AM EDT
Hi Swesh,
Thank you for helping here!
Can you Please suggest how to connect this azure registered app in spfx, i already tried MS Graph explorer to test these apis but i want to know how to connect app to spfx and how to use service accpunt as only service accpunt will have access to read outlook properties (read locations, block meeting rooms)
Than you in advance for help!!
Swesh SRank #463 · 5.4K reputationPosted Sep 13, 2024, 2:50 PM EDT
Hi Prachi,
You are looking for a whole solution, cut this into pieces
1. Register an app in Azure for MS Graph, follow these steps
https://learn.microsoft.com/en-us/graph/auth-register-app-v2
2. Once the app is registered, you would be able to get access token for an account following these steps
https://learn.microsoft.com/en-us/graph/auth-v2-user?tabs=http
3. You need to create meetings / book meeting rooms based on outlook locations pre-built or configured using service account following the steps below
https://learn.microsoft.com/en-us/graph/api/resources/onlinemeeting?view=graph-rest-1.0
https://learn.microsoft.com/en-us/graph/choose-online-meeting-api
4. Try api tools like POSTMAN with the access token generated using step 2 and see how if it succeeds.
https://learn.microsoft.com/en-us/graph/use-postman
Once all done, you can use the regular method of building the logic in spfx webpart.
Hope this helps
Thanks
Swesh
Aman GuptaRank #193 · 12.4K reputationPosted Sep 14, 2024, 6:17 AM EDT
Hi Prachi,
To connect your SPFx (SharePoint Framework) web part with Microsoft Graph and manage Outlook locations, meeting rooms, and meeting operations (block, cancel, edit), follow these steps:
1. Set Up Microsoft Graph Permissions
These can be delegated (for user-based permissions) or application permissions (for service account scenarios).
2. Add Azure AD App to SharePoint
3. Install Required NPM Packages
You'll need the following packages in your SPFx solution:
4. Configure Microsoft Graph Client
In your SPFx web part, you need to configure the Microsoft Graph client. The @pnp/graph package helps with this.
Example to get started:
import { graph } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/calendars"; import { MSGraphClient } from '@microsoft/sp-http'; public async getOutlookLocations(): Promise { // Make sure you have a valid MSGraphClient context this.context.msGraphClientFactory .getClient() .then((client: MSGraphClient): void => { client.api("/me/findRooms") .get((error, response: any) => { if (error) { console.error(error); return; } console.log("Available rooms: ", response.value); }); }); }5. Blocking/Managing Meeting Rooms and Events
Use Microsoft Graph API's Calendar endpoint to block rooms or manage meetings:
client.api('/me/events').post({ subject: 'Your Meeting', body: { contentType: 'HTML', content: 'Meeting Content' }, start: { dateTime: '2024-09-20T14:00:00', timeZone: 'Pacific Standard Time' }, end: { dateTime: '2024-09-20T15:00:00', timeZone: 'Pacific Standard Time' }, location: { displayName: 'Conference Room' }, attendees: [{ emailAddress: { address: '[email protected]', name: 'Conference Room' }, type: 'required' }] });6. Handling Authentication in SPFx
If you're using delegated permissions (i.e., the service account), you must authenticate the user.
this.context.aadHttpClientFactory .getClient('https://graph.microsoft.com') .then((client: AadHttpClient) => { client .get('https://graph.microsoft.com/v1.0/me/events', AadHttpClient.configurations.v1) .then(response => response.json()) .then(events => console.log(events)); });Note: This code examples are taken from my exisiting code project, you can change it according to your requirments.
Swesh SRank #463 · 5.4K reputationPosted Sep 21, 2024, 4:19 AM EDT
Hi Prachi,
1. how to use service accpunt as only service accpunt will have access to read outlook properties (read locations, block meeting rooms)
follow this MS article to authenticate a particular user - https://learn.microsoft.com/en-us/graph/auth-v2-user?tabs=http
to get read only access to the outlook meeting rooms - https://learn.microsoft.com/en-us/exchange/recipients/room-mailboxes?view=exchserver-2019
Permissions lists in general - https://learn.microsoft.com/en-us/graph/permissions-reference
2. how to connect app to spfx
actually Aman has provided a code sample below, for your ready to use I am attaching a couple of code snippets for ease of your use
Web Part Code (React Example)
src/webparts/myGraphWebPart/MyGraphWebPart.ts
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base'; import { MSGraphClient } from '@microsoft/sp-http'; import * as React from 'react'; import * as ReactDom from 'react-dom'; import { IMyGraphWebPartProps } from './IMyGraphWebPartProps'; import MyGraphWebPartComponent from './components/MyGraphWebPartComponent'; export default class MyGraphWebPart extends BaseClientSideWebPart { public render(): void { const element: React.ReactElement = React.createElement( MyGraphWebPartComponent, { graphClient: this.context.msGraphClientFactory.getClient() } ); ReactDom.render(element, this.domElement); } }src/webparts/myGraphWebPart/components/MyGraphWebPartComponent.tsx
import * as React from 'react'; import { MSGraphClient } from '@microsoft/sp-http'; export interface IMyGraphWebPartComponentProps { graphClient: Promise; } export interface IMyGraphWebPartComponentState { userDisplayName: string; } class MyGraphWebPartComponent extends React.Component { constructor(props: IMyGraphWebPartComponentProps) { super(props); this.state = { userDisplayName: '' }; } public componentDidMount(): void { this.props.graphClient.then(client => { client .api('/me') .get((error, response: any, rawResponse?: any) => { if (response) { this.setState({ userDisplayName: response.displayName }); } }); }); } public render(): React.ReactElement { return ( Welcome, {this.state.userDisplayName} ); } } export default MyGraphWebPartComponent;