使用 Graph API 在用户邮箱中创建文件夹
Create folder in user mailbox with Graph API
想要使用图形 API 在 Exchange Online 中存在的用户邮箱中创建文件夹。
查了下,如果我用“https://graph.microsoft.com/v1.0/users/testuser01@domain.com/mailFolders”,我觉得是可以的,但是显示错误,无法创建。
当前,"Exchange> Mail.ReadWrite, MailboxSettings.ReadWrite" 分配给执行用户(admin)。
但是,它说 "Access is denied. Check credentials and try again." 权限错误吗?
还是指定的 URL 不正确?
很抱歉给您带来麻烦,但感谢您的回复。
【追加】
$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
您正在使用client credential flow to get the token to call Microsoft Graph - Create MailFolder
,因此您需要将Micrsoft Graph的Application权限Mail.ReadWrite
添加到您的AD App中。
1.Add 应用程序权限 Mail.ReadWrite
如下所示。
2.Click Grant admin consent for xxx
按钮,并确保您请求中的 $resource
是 https://graph.microsoft.com
.
更新:
这是调用 Create MailFolder
API 来创建 MailFolder 的 powershell 示例。
$uri = "https://graph.microsoft.com/v1.0/users/joyw@xxxxx.onmicrosoft.com/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
查看Graph Explorer with List mailFolders
中的结果:
想要使用图形 API 在 Exchange Online 中存在的用户邮箱中创建文件夹。 查了下,如果我用“https://graph.microsoft.com/v1.0/users/testuser01@domain.com/mailFolders”,我觉得是可以的,但是显示错误,无法创建。 当前,"Exchange> Mail.ReadWrite, MailboxSettings.ReadWrite" 分配给执行用户(admin)。 但是,它说 "Access is denied. Check credentials and try again." 权限错误吗? 还是指定的 URL 不正确? 很抱歉给您带来麻烦,但感谢您的回复。
【追加】
$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
您正在使用client credential flow to get the token to call Microsoft Graph - Create MailFolder
,因此您需要将Micrsoft Graph的Application权限Mail.ReadWrite
添加到您的AD App中。
1.Add 应用程序权限 Mail.ReadWrite
如下所示。
2.Click Grant admin consent for xxx
按钮,并确保您请求中的 $resource
是 https://graph.microsoft.com
.
更新:
这是调用 Create MailFolder
API 来创建 MailFolder 的 powershell 示例。
$uri = "https://graph.microsoft.com/v1.0/users/joyw@xxxxx.onmicrosoft.com/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
查看Graph Explorer with List mailFolders
中的结果: