Tallal Kazmi
Tallal Kazmi

Reputation: 371

Permissions required to create subscriptions on a mailbox folder while accessing GraphAPI without user

I created an app with the Application Permissions MailboxSettings.ReadWrite.

I then built a Web API to create subscriptions to mailbox folders.

I am successfully able to get the Auth Token and listen to the test notification from the app. But when I try to create a subscription I get the following error:

{
     Code: ExtensionError
     Message: Operation: Create; Exception: [Status Code: Unauthorized; Reason: Unauthorized]
}

This is how I am creating a subscription:

var subscription = new Subscription
{
    Resource = $"users/{CurrentUserId}/mailFolders('Inbox')/messages",
    ChangeType = "created,updated",
    NotificationUrl = ConfigurationManager.AppSettings["ida:NotificationUrl"],
    ClientState = Guid.NewGuid().ToString(),
    ExpirationDateTime = DateTime.UtcNow + new TimeSpan(0, 0, 15, 0)
};

var newSubscription = await graphClient.Subscriptions.Request().AddAsync(subscription);

My question is, which permissions does my App need to have create a subscription?

I am using Microsoft Graph access without a user. https://learn.microsoft.com/en-us/graph/auth-v2-service. I want to run my API unattended.

Upvotes: 1

Views: 237

Answers (1)

Joy Wang
Joy Wang

Reputation: 42063

According to the doc, the Mail.Read permission will be enough. You need admin consent the permission for the AD App, see this link.

enter image description here

Upvotes: 1

Related Questions