Featured image of post Graph API in a Nutshell

Graph API in a Nutshell

The Microsoft Graph API is a unified interface that provides access to Microsoft 365 services, including Office 365, Azure Active Directory (Azure AD), SharePoint, Teams, and more.

Its like the “one ring” - but in the cloud :)

Before Graph API existed, we had to code against with multiple APIs, each specific to a product like Exchange, SharePoint, or Active Directory.

This frankly sucked.. :)

The GraphAPI brought all these old APIS into one place..


πŸ› The Early Days: APIs Before Graph API

Before Microsoft introduced Graph API, developers had to use separate APIs for different services:

Legacy APIPurpose
Exchange Web Services (EWS)Access emails, calendars, contacts in Exchange
SharePoint REST APIManage SharePoint documents and lists
Azure AD Graph APIQuery and manage Azure Active Directory
Office 365 APIsWork with Office services (deprecated)
Skype for Business APICommunicate with Skype for Business (now Teams)

The problem with this approach? Inconsistent authentication, different endpoints, and varied permissions for each API.

Microsoft needed a single API to unify these services.


πŸš€ The Birth of Microsoft Graph API (2015)

In November 2015, Microsoft introduced the Graph API as a RESTful, unified API for Microsoft cloud services.

Key Benefits of Graph API:
βœ… One API for all Microsoft 365 services
βœ… Consistent authentication using OAuth 2.0
βœ… Access multiple services (Office, AD, Teams, OneDrive, etc.)
βœ… Scalable and cloud-first design

Instead of querying Exchange, SharePoint, and Azure AD separately, developers could now use Graph API for everything.


🏒 How Microsoft Graph API Relates to Office 365

Office 365 is a cloud-based productivity suite that includes Word, Excel, Outlook, Teams, SharePoint, OneDrive, and more.

Graph API allows developers to integrate with Office 365 data and automate tasks:

Office 365 FeatureGraph API Capabilities
Outlook MailRead, send, and organize emails
Outlook CalendarSchedule events, invite attendees
OneDriveUpload, download, and manage files
TeamsCreate channels, post messages, manage users
SharePointRetrieve documents, manage lists
Word, Excel, PowerPointEdit and process Office files

Example: Retrieving Emails Using Graph API

1
2
3
4
5
import requests

headers = {"Authorization": f"Bearer {token['access_token']}"}
response = requests.get("https://graph.microsoft.com/v1.0/me/messages", headers=headers)
print(response.json())

C# Example

1
2
var response = await httpClient.GetAsync("https://graph.microsoft.com/v1.0/me/messages");
Console.WriteLine(await response.Content.ReadAsStringAsync());

πŸ” How Microsoft Graph API Integrates with Azure Active Directory

Azure Active Directory (Azure AD) is Microsoft’s cloud-based identity and access management service. It controls authentication for Office 365, Azure, and enterprise applications.

How Graph API Works with Azure AD:

  1. User Authentication – Uses OAuth 2.0 for secure logins.
  2. User & Group Management – Manage users, groups, and permissions.
  3. Security & Compliance – Retrieve audit logs, security alerts, and compliance reports.
  4. Enterprise Apps – Integrate with third-party applications.

Example: Retrieving User Details from Azure AD

Python Example

1
requests.get("https://graph.microsoft.com/v1.0/users", headers=headers)

C# Example

1
await httpClient.GetAsync("https://graph.microsoft.com/v1.0/users");

Example: Managing Groups in Azure AD

Python Example

1
requests.post("https://graph.microsoft.com/v1.0/groups", headers=headers, json={"displayName": "Developers", "mailNickname": "devs"})

C# Example

1
2
3
var groupData = new { displayName = "Developers", mailNickname = "devs" };
var content = new StringContent(JsonConvert.SerializeObject(groupData), Encoding.UTF8, "application/json");
await httpClient.PostAsync("https://graph.microsoft.com/v1.0/groups", content);

πŸ“… Key Milestones in the Evolution of Graph API

YearEvent
2015Microsoft Graph API launched
2017Added Teams, Planner, and Outlook support
2019Introduced Security & Compliance API
2021Improved OneDrive, SharePoint, and Excel integrations
2023AI-powered automation & Copilot integration

πŸ”„ Transition from Legacy APIs to Graph API

Azure AD Graph API vs. Microsoft Graph API

  • Azure AD Graph API was the original API for Active Directory.
  • Microsoft Graph API replaced it with enhanced security, better performance, and more features.

Azure AD Graph API Deprecation Timeline:

  • Deprecated in June 2023.
  • Developers must migrate to Microsoft Graph API.

Exchange Web Services (EWS) vs. Graph API

  • EWS was the old method to access emails and calendars.
  • Graph API is now recommended for Outlook data.