Introduction
Microsoft Graph API serves as a powerful gateway to access Microsoft 365 services, allowing developers to integrate data and automate workflows efficiently. When building a custom connector, leveraging Graph API enhances the capabilities of Power Platform applications, enabling seamless authentication and interaction with Microsoft services like Outlook, SharePoint, Teams, and OneDrive.
In this guide, we will explore the step-by-step process of integrating Microsoft Graph API into a custom connector in Power Automate or Power Apps.
Step 1: Register an Application in Azure AD
Before accessing Graph API, you must register an application in Azure Active Directory (Azure AD) to obtain authentication credentials.
- Navigate to Azure Portal.
- Go to Azure Active Directory → App registrations.
- Click New registration and enter:
- Name: Your custom connector app name
- Supported account types: Choose appropriate option
-
Redirect URI: Required for authentication (e.g.,
https://login.microsoftonline.com/common/oauth2/nativeclient
)
- Click Register, and note the Application (client) ID and Tenant ID.
Step 2: Configure API Permissions
To allow your connector to access Graph API, you need to assign API permissions:
- Go to your registered app → API permissions.
- Click Add a permission → Microsoft Graph.
- Choose Delegated or Application permissions, depending on your use case.
- Grant necessary permissions such as:
-
User.Read
(Read user profiles) -
Mail.Read
(Access emails) -
Files.ReadWrite
(Manage files on OneDrive)
-
- Click Grant admin consent to approve permissions.
Step 3: Generate Authentication Credentials
To authenticate requests, generate a client secret or use certificates:
- Go to Certificates & secrets → New client secret.
- Enter a description and expiration period.
- Click Add and copy the Client Secret Value (it will not be visible again).
Step 4: Create the Custom Connector in Power Automate
Now, set up the custom connector using Graph API in Power Automate:
- Open Power Automate → Custom Connectors.
- Click Create a custom connector → Blank connector.
- Enter a name, then move to the Security section:
- Choose OAuth 2.0 authentication.
- Set
https://login.microsoftonline.com/{tenant_id}/oauth2/token
as the token URL. - Provide Client ID and Client Secret from Azure.
- Define the scope (e.g.,
https://graph.microsoft.com/.default
).
Step 5: Define API Endpoints
To interact with Graph API, configure requests within the custom connector:
- In Definition, click New action.
- Set the summary and operation ID (e.g.,
GetUserDetails
). -
Configure the request:
- URL:
https://graph.microsoft.com/v1.0/me
- Method:
GET
- Headers:
{ "Authorization": "Bearer {access_token}" }
- URL:
Test the request and validate the API response.
Step 6: Test and Deploy the Connector
- Save and publish the custom connector.
- Create a Power Automate flow or Power Apps integration using the connector.
- Monitor API calls using Graph Explorer or Azure Application Insights.
Conclusion
By integrating Graph API into a custom connector, you unlock advanced capabilities in Power Platform solutions. Whether accessing user profiles, emails, files, or Teams data, Microsoft Graph enables powerful automation and data retrieval.
Real-World Scenario: Automating Employee Onboarding with Microsoft Graph API
Use Case
A company uses Microsoft 365 for communication and collaboration. To streamline the onboarding process, they want to automate the creation of new employees’ Microsoft Teams accounts, assign them to Teams channels, and provision OneDrive folders using Graph API and a custom connector in Power Automate.
Solution Overview
Using Microsoft Graph API, the custom connector in Power Automate will:
- Retrieve employee details from an HR database.
- Create a new Teams user and assign them to relevant channels.
- Provision a OneDrive folder for storing their onboarding documents.
- Send a welcome email with login credentials and company resources.
Step-by-Step Implementation
Step 1: Set Up the Custom Connector
Follow the steps in the previous guide to configure authentication using Azure AD and Graph API permissions, ensuring the connector has access to:
-
User.ReadWrite.All
(for managing users) -
Group.ReadWrite.All
(for assigning Teams membership) -
Files.ReadWrite.All
(for provisioning OneDrive folders)
Step 2: Retrieve Employee Details
A Power Automate flow triggers when a new employee record is added to the HR database.
- HTTP Request to Graph API:
GET https://graph.microsoft.com/v1.0/users/{newUserEmail}
Authorization: Bearer {access_token}
- If the user does not exist, proceed to account creation.
Step 3: Create a Microsoft Teams User
- API Request to Add User:
POST https://graph.microsoft.com/v1.0/users
Content-Type: application/json
Authorization: Bearer {access_token}
- Payload:
{
"displayName": "John Doe",
"mail": "john.doe@company.com",
"passwordProfile": {
"forceChangePasswordNextSignIn": true
}
}
- This automatically creates a new Microsoft 365 user with a temporary password.
Step 4: Assign the User to Teams Channels
- Add the new employee to the "Onboarding" channel:
POST https://graph.microsoft.com/v1.0/groups/{teamId}/members
- The employee can now access training materials and orientation sessions directly from Teams.
Step 5: Provision OneDrive Folder
- Create a dedicated OneDrive folder for the new user:
POST https://graph.microsoft.com/v1.0/users/{newUserId}/drive/root/children
- This ensures employees have direct access to onboarding documents.
Step 6: Send a Welcome Email
Using Microsoft Graph API, send an email with credentials and onboarding resources:
POST https://graph.microsoft.com/v1.0/users/{newUserId}/mailfolders/inbox/messages
- Include helpful links and company policies in the email body.
Business Impact
✅ Reduced manual work—HR staff no longer need to create accounts manually.
✅ Consistent onboarding experience—every employee receives standardized training resources.
✅ Improved security—credentials are managed automatically with Azure AD authentication.
Hope you enjoy the session.
Please leave a comment below if you have any further questions.
Happy Sharing !!!
Keep Learning | Spread Knowledge | Stay blessed |
Top comments (0)