How to call Microsoft Graph APIs from a JavaScript Outlook Add-In

Anonymous
2024-09-25T12:58:17+00:00

We are developing a web-based JavaScript Add-In for Outlook which would run on Windows, Mac and Web.

And from this Add-In, we need to call Microsoft Graph APIs for downloading the Outlook user's emails and attachments.

What is the simplest way to achieve this?

Outlook | Windows | New Outlook for Windows | For home

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-09-25T13:40:10+00:00

    Hi Arun Singh5,

    Good day.

    Thank you for posting to the Microsoft Community. We are glad to assist.

    To call Microsoft Graph APIs from a JavaScript Outlook Add-In, you can follow these steps:

    Register Your Application

    First, you need to register your application in the Microsoft Entra admin center:

    • Go to the Microsoft Entra admin center.
    • Navigate to App registrations and select New registration.
    • Fill in the required fields, such as the name and redirect URI (set it to a Single-page application (SPA) with a URL like https://localhost:3000).

    Configure API Permissions

    • After registering, go to API permissions and add the necessary Microsoft Graph permissions, such as Mail.Read and Mail.ReadWrite.

    Set Up Authentication

    • Use the Microsoft Authentication Library (MSAL.js) to handle authentication in your add-in.
    • Install it via npm: npm install @azure/msal-browser

    Get an Access Token

    • Use MSAL.js to get an access token for Microsoft Graph:

    Call Microsoft Graph API

    • Use the access token to call Microsoft Graph API and download emails and attachments:

    Integrate with Outlook Add-In

    • Use the Office JavaScript API to integrate this functionality into your Outlook Add-In. For example:

    This should help you get started with calling Microsoft Graph APIs from your JavaScript Outlook Add-In.

    ,

    If you’re still need more details for this you can try contacting Get support - Microsoft 365 admin | Microsoft Learnthe support team will have access to assist remotely .

    I hope this helps let me know if this is contrary to what you need, I would still be helpful to answer more of your questions .

    Best Regards

    Community Moderator

    0 comments No comments
  2. Anonymous
    2024-09-30T12:42:43+00:00

    Hi,

    Thanks "Community Moderator" for your reply.

    We also want to understand what is the best approach to enable our Outlook Add-In to call Graph APIs for users of different tenancy. We intend to make our Outlook Add-In support multi-tenancy where we would have users from more than one organizations/companies.

    1. One potential approach, that we assume, is to ask each of our clients to set up Microsoft Azure applications. And, to be able to call MS Graph APIs, our Outlook Add-In would require to call MSAL libraries with the required OAuth details (such as AppID, scope and ClientId) of their respective Azure apps.
    2. For this, our Outlook Add-In would be required to know the OAuth details for each of our clients.
    3. But, is there a way where we can have a centralized/single/common Azure app which could further be configured to enable calling of Microsoft Graph APIs, from our Outlook Add-In, for multiple tenants? This way our Outlook Add-In will have to interact with just one Azure app and not several.
    0 comments No comments