0

want to use the Graph API to create a folder in a user's mailbox that exists in Exchange Online. As a result of the investigation, if I use "https://graph.microsoft.com/v1.0/users/[email protected]/mailFolders", I feel that it is possible, but an error is displayed and I cannot create it. Currently, "Exchange> Mail.ReadWrite, MailboxSettings.ReadWrite" is assigned to the execution user (admin). However, it says "Access is denied. Check credentials and try again." Is the permission wrong? Or is the specified URL incorrect? Sorry to trouble you, but thank you for your response.

【Append】

$body = @{
    grant_type="client_credentials"
    resource=$resource
    client_id=$ClientID
    client_secret=$ClientSecret
}
`#Get Token
$oauth = Invoke-RestMethod -Method Post -Uri $loginURL/$TenantName/oauth2/token -Body $body

API Permissions

10
  • Please show the screenshot of the API permissions of your app registration, and how did you get the access token and call the api? Commented Apr 14, 2020 at 5:36
  • Please also update the question with the way you used to get the token. Commented Apr 14, 2020 at 7:06
  • thank you for your answer.I updated it, but is it OK? Commented Apr 14, 2020 at 7:11
  • Please check my solution. Commented Apr 14, 2020 at 7:52
  • Thank you very much. I was able to execute normally with the contents you received. I would like to know the command required to actually create a folder using the Graph API in PowerShell, should it be listed as another question? I got the token with the previous method and created it with the following command. However, no error was displayed with "StatusCode = 200", but the folder was not created. I apologize for all the questions, but I would appreciate it if you could confirm. Commented Apr 14, 2020 at 8:59

1 Answer 1

1

You are using the client credential flow to get the token to call Microsoft Graph - Create MailFolder, so you need to add the Application permission Mail.ReadWrite of Micrsoft Graph to your AD App.

1.Add the Application permission Mail.ReadWrite like below.

enter image description here

enter image description here

enter image description here

2.Click the Grant admin consent for xxx button, and make sure the $resource in your request is https://graph.microsoft.com.

enter image description here

Update:

Here is a powershell sample to call Create MailFolder API to create MailFolder.

$uri = "https://graph.microsoft.com/v1.0/users/[email protected]/mailFolders"
$headers = @{
    'Content-Type' = 'application/json'
    'Authorization' = 'Bearer <access-token-here>'
}
$body = ConvertTo-Json @{
    "displayName" = "testfolder1"
}
Invoke-RestMethod -Method Post -Uri $uri -Headers $headers -Body $body 

enter image description here

Check the result in the Graph Explorer with List mailFolders:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.