Accessing mailbox folders with name containing space

GDL 20 Reputation points
2024-01-18T10:04:28.6133333+00:00

Hello, I'm using Graph API to retrieve messages from a specific mailbox folder. https://graph.microsoft.com/v1.0/users/<MAILBOX_UPN>/mailFolders/Inbox/messages works fine. When the folder name contains a space, if I try to make the same call for a well-known folder, it looks like I can just remove the space, for instance: https://graph.microsoft.com/v1.0/users/<MAILBOX_UPN>/mailFolders/SentItems/messages returns:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('<MAILBOX_UPN>')/mailFolders('SentItems')/messages",
    "value": []
}

even if the displayName of the folder is "Sent Items".

I can't make it work for a custom "Test Folder", all these calls:

  1. https://graph.microsoft.com/v1.0/users/<MAILBOX_UPN>/mailFolders/TestFolder/messages
  2. https://graph.microsoft.com/v1.0/users/<MAILBOX_UPN>/mailFolders/Test%20Folder/messages
  3. https://graph.microsoft.com/v1.0/users/<MAILBOX_UPN>/mailFolders/%22Test%20Folder%22/messages

fail with

{
    "error": {
        "code": "ErrorInvalidIdMalformed",
        "message": "Id is malformed."
    }
}

Is there a way to access folders with a space in the name without using the folder id (which requires a previous call to the /mailFolders endpoint)?

Thank you

Giampiero

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,057 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 113.8K Reputation points MVP
    2024-01-18T19:03:24.2533333+00:00

    This is not how you reference custom folders, you're supposed to use the folder ID. Only "known", built-in folders can be referred to by their name, as explained for example here: https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-1.0 For any other folder, you should use the Folder ID. You can list the set of folders to get their IDs, or search/filter for the folder in question:

    GET https://graph.microsoft.com/beta/me/mailFolders?$filter=displayName eq 'MVP DL'
    
    GET https://graph.microsoft.com/beta/me/mailFolders/AAMkAGU2MWM5NzU0LWY3MmQtNGI3OS1hNDVlLTBkMzI3OWVlNWIzZgAuAAAAAAChKSJAhlnUTIHtKSso30ThAQBIPfDMxyP-RYhY8M8xmAPVAACPwDEQAAA=/messages
    
    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.