Azure Graph API

Published On: 29 August 2023.By .

What is Azure?

Azure Graph API, also known as Microsoft Graph API, is a powerful RESTful API provided by Microsoft as part of the Azure ecosystem. It allows developers to integrate their applications with various Microsoft services, including Azure Active Directory (Azure AD), Office 365, and other Microsoft 365 services.

Azure Purpose

Authentication and Authorization

The Microsoft Graph API employs OAuth 2.0 for authentication, ensuring that only authorized applications and users can access the resources. This security mechanism safeguards sensitive email data from unauthorized access. Authentication is a critical step before accessing any resources using the Azure Graph API.

Graph API (Outlook)

The Azure Graph API provides powerful functionality to interact with mail-related resources in Microsoft 365. With the email aspect of the Azure Graph API, developers can programmatically send emails, access mailboxes, manage folders, and retrieve email data. It offers a unified and consistent API endpoint for working with mail across different Microsoft 365 services, such as Exchange Online and Outlook.com. Developers can leverage the email aspect of the Azure Graph API to automate email-related tasks, integrate mail functionality into custom applications, and build intelligent email solutions. By utilizing the Azure Graph API email aspect, developers can streamline mail operations, enhance productivity, and enable seamless integration with other Azure and Microsoft services.

Azure Access Token

Steps to Use Graph API

Steps to Set Up Azure

  1. Go to https://portal.azure.com and log in using your personal email.
  2. Search for “app registration.”
     Graph API App Registration
  3. Click to add a new registration.
    Azure App Registration Page
  4. Fill out the registration form as provided.
    Azure Graph API App Registration Form
  5. Click on “Register” and copy the Application ID.
  6. Go to “certificates and secrets.”
  7. Click on “New client secret.”
    Azure API Client Secret Page
  8. Fill out the form and press “Add.”Azure API Client Secret Form
  9. Copy the Secret ID as it will not be available in the future.
  10. Go to “API permissions,” select permissions, and press “Add.”

    Azure Graph API Permission

Authentication Using Python

Due to multifactor authentication, we are using the “msal” library.

Authentication Using Postman

  1. Go to authentication and choose OAuth 2.0.
  2. Fill in all the required details as provided.
  3. Click on “New Access Token” and use it in the “Bearer Token” field.
    azure Postman Auth
  4. A pop-up will appear; authenticate it, and you will receive an access token.

Azure Graph API End-Points (Email)

  1. Send an Email

    • Endpoint: POST /users/{id}/sendMail
    • Description: Allows sending an email on behalf of a user.
    • Request Body: Includes email details such as recipients, subject, body, and attachments.
  2. Access Mail Folders
    • Endpoint: GET /me/mailFolders or GET /users/{id}/mailFolders
    • Description: Retrieves a list of mail folders for the authenticated user or a specific user.
    • Use Cases: Accessing the Inbox, Sent Items, Drafts, and other custom folders.
  3. Retrieve Inbox Messages
    • Endpoint: GET /me/messages or GET /users/{id}/messages
    • Description: Retrieves a list of email messages from the authenticated user’s mailbox or a specific user’s mailbox.
    • Parameters: Supports filtering, sorting, and searching for specific messages.
  4. Access Drafts and Sent Items
    • Endpoint: GET /me/mailFolders/{folder-id}/messages or GET /users/{id}/mailFolders/{folder-id}/messages
    • Description: Accesses email messages within a specific mail folder, such as Drafts or Sent Items.
  5. Create and Reply to Messages
    • Endpoint: POST /me/messages or POST /users/{id}/messages
    • Description: Allows creating new email messages or replying to existing messages.
    • Request Body: Includes message details and content.
  6. Work with Message Attachments
    • Endpoint: GET /me/messages/{message-id}/attachments or GET /users/{id}/messages/{message-id}/attachments
    • Description: Retrieves attachments associated with a specific email message.
    • Use Cases: Download attachments or add new attachments to messages.
  7. Filter and Search Emails
    • Endpoint: GET /me/messages or GET /users/{id}/messages
    • Description: Supports filtering and searching for specific email messages based on various criteria.
    • Parameters: Allows narrowing down results based on date, sender, subject, etc.
  8. Manage Mail Folders
    • Endpoint: POST /me/mailFolders or POST /users/{id}/mailFolders
    • Description: Enables creating new mail folders or updating existing ones.
    • Use Cases: Organizing emails into custom folders or managing folder properties.

Related content

That’s all for this blog

Go to Top