Reputation: 5
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
Upvotes: 0
Views: 2131
Reputation: 42063
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.
2.Click the Grant admin consent for xxx
button, and make sure the $resource
in your request is https://graph.microsoft.com
.
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
Check the result in the Graph Explorer with List mailFolders
:
Upvotes: 1