如何使用Microsoft Graph API获取邮件子文件夹ID及Inbox下Test子文件夹详情
Got it, let's break down why your current request is failing and how to fix it: The Microsoft Graph API doesn't let you reference custom mail subfolders directly by their display name in the URL path. Segments like Inbox work because it's a well-known folder with a reserved identifier, but subfolders like Test need to be accessed using their unique folder ID or via filtered child folder queries.
Here are the two most straightforward ways to get the details of your Test subfolder:
Option 1: Fetch the Test folder ID first, then get its details
Retrieve the Test folder's ID by querying Inbox's child folders and filtering by display name:
GET https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/childFolders?$filter=displayName eq 'Test'This will return a list of folders matching the name (you'll likely get just one result). Look for the
idfield in the response—it'll be a long, unique string likeAAMkAG...AAA=.Use the ID to get the folder details:
Replace{test-folder-id}with the ID you found in the previous step:GET https://graph.microsoft.com/v1.0/me/mailFolders/{test-folder-id}
Option 2: Get the Test folder details in a single request
If you don't need to reuse the folder ID later, you can combine the query to get the details directly using $filter and $select (to limit the response to just the details you care about):
GET https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/childFolders?$filter=displayName eq 'Test'&$select=id,displayName,totalItemCount,unreadItemCount
This will return the full details of the Test folder in one go.
Bonus: Access nested subfolders (Test1 under Test, Test2 under Test1)
Once you have the ID of Test, you can repeat the same pattern for deeper folders:
- To get
Test1details:GET https://graph.microsoft.com/v1.0/me/mailFolders/{test-folder-id}/childFolders?$filter=displayName eq 'Test1' - To get
Test2details, use the ID ofTest1in the same way.
内容的提问来源于stack exchange,提问作者Kylie

