You are currently viewing Introduction to Microsoft Graph API with examples

Introduction to Microsoft Graph API with examples

  • Post author:
  • Post category:Graph API
  • Reading time:12 mins read

In today’s rapidly evolving digital world, both businesses and individuals rely heavily on a multitude of Microsoft services and applications to enhance productivity, foster collaboration, and enable seamless communication. Managing data and interactions across these services can become a challenge.

Microsoft Graph API, a game-changing tool that provides developers with a single endpoint to access and interact with data and services across the Microsoft ecosystem.


What is Microsoft Graph API?

The Microsoft Graph API is a RESTful web service that is used as a gateway to access a wide array of data and services from various Microsoft cloud offerings, including Microsoft 365, Azure Active Directory, OneDrive, Outlook, SharePoint, Microsoft Teams, Planner, To Do, Viva Insights, Windows, Enterprise Mobility + Security and many of the other services that provided by Microsoft.

  • Microsoft Graph API simplifies data integration and enhances cross-platform communication.
  • With Microsoft Graph API, Developers can use a single API call to retrieve data from multiple services without the need to interact with each service separately, without the Graph API, you have to learn how each API work.
  • Microsoft Graph’s capabilities, spanning various Microsoft Cloud services. These include Teams, Groups, Chats, Calendars, Files, Users, Devices, Meetings, and more.
Microsoft Graph API

What’s the microsoft graph aPI explorer?

In the rapidly evolving of digital transformation, data integration and seamless connectivity play a pivotal role in enhancing workflows and user experiences.

  • Microsoft Graph API Explorer has emerged as a user-friendly tool for developers seeking to tap into the potential of data integration across Microsoft Cloud services.
  • Microsoft Graph API Explorer has its own significance in unlocking the true power of data integration.
  • Microsoft Graph API Explorer is a web-based tool that provides you with an interactive interface to explore and experiment with Microsoft Graph API’s vast capabilities.

How to Sign in to microsoft graph aPI explorer?

To sign in to Microsoft Graph, follow these steps:

Steps

  1. Open a web browser and navigate to the Microsoft Graph Explorer website: https://developer.microsoft.com/en-us/graph/graph-explorer
  2. Click on the “Sign in with Microsoft” button located in the upper-right corner of the page.
  3. A new window will appear, prompting you to enter your Microsoft account credentials or the credentials associated with your Microsoft 365 account.
  4. Enter your email address and password, then click “Sign in.”
  5. After successful authentication, you will be granted access to Microsoft Graph Explorer and can start using it to interact with Microsoft Graph APIs and explore various Microsoft 365 services.

When you sign in to Graph Explorer and run the same query, the response is returned with real data from the tenant that you signed in to.

You can browse Microsoft Graph explorer from Graph explorer link.

7 24 2023 5 18 11 PM | Power Platform Geeks
  1. [GET,POST,PUT,PATCH,DELETE], represent different types of requests that clients can make to interact with a server.
    • The GET method is used to retrieve data from the server. GET requests are read-only and should not have any side effects on the server or the data.
    • The POST method is used to submit data to the server to create a new resource.
    • The PUT method is used to update an existing resource on the server.
    • The PATCH method is used to partially update an existing resource on the server. Unlike PUT, a PATCH request only includes the changes that need to be applied to the resource, not the entire resource representation.
    • The DELETE method is used to request the removal of a specified resource from the server.
  2. For the HTTP request, you can either select a sample query from the menu at the left in number 3, which fills in the query field, or you can choose to manually type your request in the field.
  3. Sample queries that you can use in part 2″ the query field”.
  4. The response to the query that you call through Graph API.

microsoft graph aPI examples

Example 1: Graph API Get User’s Profile

In this example, you can retrieve the profile information of the currently signed-in user.

using the Get request
https://graph.microsoft.com/v1.0/me

Example 2: Graph API List OneDrive Files

In this example, you can get a list of files in the users OneDrive

using the Get request
https://graph.microsoft.com/v1.0/me/drive/root/children

Example 3: Microsoft Graph API to send email

In this example, you can send an email on behalf of the signed-in user.

using the Post request
https://graph.microsoft.com/v1.0/me/sendMail
{
    "message": {
        "subject": "Hello from Graph Explorer",
        "body": {
            "contentType": "Text",
            "content": "This is a test email sent from Graph Explorer!"
        },
        "toRecipients": [
            {
                "emailAddress": {
                    "address": "HebaKamal87@outlook.com"
                }
            }
        ]
    }
}
graph | Power Platform Geeks

This is the mail that sends from graph explorer

graph2 | Power Platform Geeks

Example 4: Graph explorer List Events from Calendar

In this example, you can retrieve a list of events from the user’s calendar.

https://graph.microsoft.com/v1.0/me/events

You have to add some permission to run your query for example to get the event calendar you need to consent to one of the permissions on the Modify permissions tab.

graph2 1 | Power Platform Geeks

Example 5: Microsoft graph API for Teams

In this example, you can get a list of Microsoft Teams that the user is a member of.

https://graph.microsoft.com/v1.0/me/joinedTeams
graph3 | Power Platform Geeks

Microsoft Graph API and SharePoint

Microsoft Graph and SharePoint are two interconnected technologies offered by Microsoft that play essential roles in modern collaborative and data-driven environments.

Lets explore some examples on how to use Microsoft Graph to get information from SharePoint using Microsoft Graph API explorer.

Ex1: Get information about the Root site

https://graph.microsoft.com/v1.0/sites/root/

Ex2: Get information about a Subsite

for example, I want to get the subsite PowerApps that is located under the base URL Mel.sharepoint.com

https://graph.microsoft.com/v1.0/sites/Mel.sharepoint.com:/sites/PowerApps:

Ex3: List all the lists in the subsite

https://graph.microsoft.com/v1.0/sites/Mel.sharepoint.com:/sites/PowerApps:/lists

Ex4: List all items in a specific list

https://graph.microsoft.com/v1.0/sites/Mel.sharepoint.com:/sites/PowerApps:/lists/YourListID/items

Ex5: Apply filter on the items of the list

https://graph.microsoft.com/v1.0/sites/Mel.sharepoint.com:/sites/PowerApps:/lists/YourListID/items$filter=fields/Title eq 'Contoso Home'

conclusion

In conclusion, Microsoft Graph API has revolutionized the way developers interact with data and services across the Microsoft ecosystem. By providing a unified endpoint, the API streamlines data integration, fosters collaboration, and enhances the overall user experience.

Join us

Heba Kamal

Microsoft MVP, MCT, Technical Speaker, Blogger, and Microsoft 365 and Power Platform Consultant.