MS Graph API v1.0 - Navigating Multi-level Folders

Mark Benson 21 Reputation points


I am trying to make an automated script in PHP that copies or moves mail to a user's mail folder using the Graph 1.0 API and the v1.82.0 msgraph-sdk-php SDK. The problem I am running into is that some folders I need to access are several folders deep and I am struggling to understand how to build a 'destination' to move or copy the mail to.

Example. I want to move message ID 123456789 to /Test2/Test22/Test222

I make a POST request to "/users/{id}/messages/{id}/move"

In the body I give a destinationId for the folder to move to, but I do no know what kind of GET request I need to make to traverse the folder structure to get the ID for the Test222 folder.

Can someone fill me in on how to do this?


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

Accepted answer
  1. HarmeetSingh7172 4,811 Reputation points

    Hello @Mark Benson

    Thanks for reaching out!

    You can list down the childFolders of a MailFolder using List ChildFolders endpoint. Endpoint: GET /me/mailFolders/{id}/childFolders

    Using above endpoint, you'll get the ID of the childFolder in response and post that, you can replace the parentMailfolderID with the childFolderID in endpoint, which will further list the children of that childFolder. More precisely, you need to make multiple calls to get into the last child folder.

    Please find the detailed steps below:

    GET - will list all the mailFolders
    GET{mailFolderID} - get the MailFolder details
    GET{mailFolderID}/childFolders - List childFolders of MailFolder
    GET{childFolderID}/childFolders - mailFolderID replaced with childFolderID (Repeat until you reach the last childFolder)

    Now use the last ChildFolderID as a destinationID in the request body of Move Messages Endpoint


    Content-type: application/json  
      "destinationId": "ChildFolderID"  

    Hope this helps.

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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful