How to get email messages in all delegated folders, rather than a specific folder

Andrew Earl 105 Reputation points
2024-08-07T10:11:41.3066667+00:00

Hi, I am using Microsoft Graph API via Postman and trying to get all the messages in a delegate's email account, rather than messages in a specific folder.

The delegate has given access to the account to me in Outlook.

When I use

https://graph.microsoft.com/v1.0/users/user@company.com/mailfolders('Inbox')/messages

I get the emails in the delegated user's inbox as expected

However when I use

https://graph.microsoft.com/v1.0/users/user@company.com/messages

I get the response

{
    "error": {
        "code": "ErrorItemNotFound",
        "message": "The specified object was not found in the store., Default folder AllItems not found."
    }
}

I have set the delegated permission Mail.Read.Shared.

Is there a way to get all messages for the user rather than a specific folder? Thanks

Microsoft Exchange Online
Outlook
Outlook
A family of Microsoft email and calendar products.
3,901 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,113 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rohit Raghuwanshi - MSFT 475 Reputation points Microsoft Vendor
    2024-08-08T19:42:54.62+00:00

    Hi Andrew Earl,

    Thank you for reaching out to Microsoft!

    When attempting to retrieve shared mailbox folders via the Graph API, it's necessary to share a specific folder from Outlook. While it's possible to share the Inbox and other folders, such as Sent Items, with other users through delegated access, the AllItems folder is not shared. This is the folder that is accessed via the endpoint users/user@company.com/messages, which may be causing the error you're encountering.

    To retrieve all emails from a user's mailbox with a single API call, you can use Application permissions with the GET /users/{id | userPrincipalName}/messages/ endpoint. This enables you to access all emails in the user's mailbox through one API request.

    Please ensure the application is granted the following permission to access messages: Mail.ReadBasic.All, Mail.Read

    Documentation reference: https://learn.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=http

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.