How to Call Microsoft Graph API from Copilot Agent
Microsoft Copilot Studio
Feb 4, 2025 7:00 PM

How to Call Microsoft Graph API from Copilot Agent

by HubSite 365 about Deepak Shrivastava [MVP]

Senior Manager at Ernst & Young | Microsoft MVP | MCT

Citizen DeveloperMicrosoft Copilot StudioLearning Selection

Microsoft Graph API Copilot Agent actions tutorial publish flow Teams channel #copilot #microsoftgraph #powerautomate

Key insights

  • Register an App in Azure AD: Essential for authentication before calling the Microsoft Graph API. Steps include navigating to the Microsoft Entra Admin Center, registering a new app, adding API permissions, and creating a client secret.

  • Call Microsoft Graph API from a Copilot Agent: You can use either Power Automate (recommended for no-code) or custom plugins in Copilot Studio.

    • Using Power Automate: Create a flow with "Instant Cloud Flow" as the trigger and use the "HTTP" action to call the API. Configure authentication with OAuth 2.0 using Azure AD app credentials.

    • Using Custom Plugin in Copilot Studio: Define an HTTP API connection and configure OAuth 2.0 authentication. Add endpoints for Graph API like /me or /users.

  • Example Use Cases: Fetch user profile details, get a list of Teams meetings, send an Outlook email, or create a new OneDrive file using specific endpoints like /me/events or /me/sendMail.

Introduction to Calling Microsoft Graph API from Copilot Agent

In the rapidly evolving digital landscape, the integration of various platforms and APIs has become crucial for enhancing productivity and streamlining operations. One such integration is calling the Microsoft Graph API from a Copilot Agent, as demonstrated in a recent YouTube tutorial by Deepak Shrivastava, an MVP in the field. This tutorial provides a comprehensive guide on how to effectively utilize Microsoft Graph API through Copilot Agent, leveraging tools like Power Automate and Microsoft Copilot Studio. Moreover, it explores the process of publishing your flow to a Teams channel, offering a seamless experience for users within an organization.

Setting Up Azure AD for Authentication

Before diving into the process of calling the Microsoft Graph API, it is essential to set up an Azure AD app to obtain access tokens. This step is critical for authentication and ensures secure communication between the Copilot Agent and Microsoft Graph API. The process involves several key steps:
  • Navigate to the Microsoft Entra Admin Center (Azure AD) and go to App registrations.
  • Create a new registration by entering a name, such as "CopilotGraphAPI".
  • Select "Accounts in this organizational directory only" and click Register.
  • Add API permissions by selecting Microsoft Graph and choosing the necessary permissions, such as User.Read and Mail.Send.
  • Grant admin consent for the organization to enable these permissions.
  • Create a Client Secret under Certificates & secrets and copy the Application (client) ID, Directory (tenant) ID, and Client Secret for future use.
These steps lay the foundation for securely calling the Microsoft Graph API from a Copilot Agent.

Calling Microsoft Graph API via Copilot Agent

Once the Azure AD setup is complete, you can proceed to call the Microsoft Graph API using either Power Automate or Custom Plugins in Copilot Studio. Each option offers unique advantages and caters to different user needs. Option 1: Using Power Automate
Power Automate is recommended for users seeking a no-code solution. To call the Microsoft Graph API using Power Automate:
  • Create a Flow in Power Automate by selecting New Flow and Instant Cloud Flow.
  • Choose "When invoked from a Copilot agent" as the trigger.
  • Add an "HTTP" action to call the Microsoft Graph API, specifying the method (GET or POST) and the URL, such as https://graph.microsoft.com/v1.0/me.
  • Set the headers to include the Authorization (Bearer ) and Content-Type (application/json).
  • Authenticate using OAuth 2.0 with the Azure AD app credentials.
  • Finally, add a "Response" action to return the API results to Copilot.
Option 2: Using Custom Plugin in Copilot Studio
For users who prefer a more tailored approach, creating a custom plugin in Copilot Studio is a viable option:
  • Open Copilot Studio and navigate to Plugins to create a new plugin.
  • Define an HTTP API connection and configure authentication using OAuth 2.0 with Azure AD.
  • Add endpoints for the Graph API, such as /me or /users, and save the integration.
  • Test the integration to ensure it functions as expected.
Both methods provide flexibility and cater to different levels of technical expertise, allowing users to choose the approach that best suits their needs.

Exploring Use Cases

The ability to call the Microsoft Graph API from a Copilot Agent opens up a wide range of possibilities for enhancing productivity and automating tasks. Some example use cases include:
  • Fetching user profile details using the /me endpoint.
  • Retrieving a list of Teams meetings with the /me/events endpoint.
  • Sending an Outlook email through the /me/sendMail endpoint.
  • Creating a new OneDrive file using the /me/drive/root/children endpoint.
These use cases demonstrate the versatility of integrating Microsoft Graph API with Copilot Agent, providing users with powerful tools to streamline their workflows.

Challenges and Considerations

While the integration of Microsoft Graph API with Copilot Agent offers numerous benefits, it also presents certain challenges and considerations. One major challenge is ensuring proper authentication and security when accessing sensitive data through the API. It is crucial to follow best practices for securing access tokens and managing permissions to protect organizational data. Additionally, balancing the ease of use with the complexity of integration can be challenging. While Power Automate provides a user-friendly interface for no-code solutions, it may not offer the same level of customization as custom plugins in Copilot Studio. Therefore, users must carefully evaluate their requirements and choose the approach that aligns with their technical capabilities and project goals.

Conclusion

In conclusion, calling the Microsoft Graph API from a Copilot Agent is a powerful way to enhance productivity and automate tasks within an organization. By setting up Azure AD for authentication and choosing the appropriate method for integration, users can unlock a wide range of possibilities for leveraging Microsoft Graph API. Whether using Power Automate for a no-code solution or custom plugins for a tailored approach, the integration offers flexibility and scalability to meet diverse user needs. As organizations continue to embrace digital transformation, such integrations will play a pivotal role in driving efficiency and innovation.

Microsoft Graph - Unlock Microsoft Graph API: Power Automate Meets Copilot for Seamless Integration! #copilot #microsoftgraph

Keywords

Microsoft Graph API, Copilot Agent integration, Power Automate tutorial, Microsoft API call guide, Copilot automation tips, Graph API with Copilot, Microsoft automation tools, Power Automate and Graph.