Create mailbox folder with Graph API

ort_tt 21 Reputation points
2020-04-14T10:50:39.863+00:00

I want to use the Graph API to create a folder in a mailbox that belongs to Exchange Online.
After getting the token, I was able to create a folder with the following command.
However, it cannot be created as a child folder of the specified folder.
Is it possible to create directly under the inbox?

$url = "https://graph.microsoft.com/v1.0/users/testuser01@keyman .com/mailFolders/inbox"
$Body = @"
{
"displayName": "TestFolder",
"parentFolderId": "**********"
}
"@

Invoke-RestMethod -Uri $url -Method Post -Body $Body -ContentType 'application/json; charset=utf-8' -Headers $headerParams | ConvertTo-Json

Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
12,705 questions
No comments
{count} votes

Accepted answer
  1. soumi-MSFT 11,606 Reputation points Microsoft Employee
    2020-04-14T13:28:27.387+00:00

    @ort_tt , I just tested this api and it worked for me. Let me share the detailed steps below:

    1. Use Authorization Code Grant Flow to fetch a token for your App from AAD.
    2. Once you have the code use it to request for an access_token from AAD. make sure the following delegated permission "Mail.ReadWrite" is present on the app registration that is being used here.
    3. Call the following Graph API.

    API: https://graph.microsoft.com/v1.0/userPrincipalName/mailFolders/{id}/childFolders

    Eg:
    https://graph.microsoft.com/v1.0/me/mailFolders/AAMkADAwZmE5NGU1LWJlYzAtNGE0ZS1hZDI4LWZmNmU0MDdjNzgyZQAuAAAAAABh0v7KYQaiRob9eDRfUq1JAQDBRn5LIsmdTKmOCwZeGkgvAAAAAAEMAAA=/childFolders

    Body:
    {
    "displayName": "{Child Folder Name}",
    }

    This is the ID for my inbox "AAMkADAwZmE5NGU1LWJlYzAtNGE0ZS1hZDI4LWZmNmU0MDdjNzgyZQAuAAAAAABh0v7KYQaiRob9eDRfUq1JAQDBRn5LIsmdTKmOCwZeGkgvAAAAAAEMAAA="

    Once you make the api call, you should get status 200 OK and the child folder should be present in your outlook:

    7413-outlook.png

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.


0 additional answers

Sort by: Most helpful