How are you authenticating? If using the client credentials flow, there is no logged in user, hence you cannot user /me. Use /user/{userId}/mailboxSettings instead.
Graph explorer uses delegate permissions, /me works fine therein.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have an issue using Graph API for Outlook.
When I use Graph explorer I can request this endpoint:
https://graph.microsoft.com/v1.0/me/mailboxSettings
There is no issue at all.
But when doing the same call in a Blazor Server app with MSAL I get this error:
{"error":{"code":"MailboxNotEnabledForRESTAPI","message":"The mailbox is either inactive, soft-deleted, or is hosted on-premise."}}
Here is the code:
// Program.cs
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddMicrosoftIdentityConsentHandler();
string[]? scopes = builder.Configuration.GetSection("GraphApi:Scopes").Get<string[]>();
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration,
subscribeToOpenIdConnectMiddlewareDiagnosticsEvents: true)
.EnableTokenAcquisitionToCallDownstreamApi(scopes)
.AddDownstreamApi("GraphApi", builder.Configuration.GetSection("GraphApi"))
.AddInMemoryTokenCaches();
builder.Services.AddControllersWithViews()
.AddMicrosoftIdentityUI();
builder.Services.AddAuthorization(options => { options.FallbackPolicy = options.DefaultPolicy; });
// Home.razor
private async Task UseDownStreamApi(MouseEventArgs arg)
{
try
{
using HttpResponseMessage response = await DownstreamApi.CallApiForUserAsync("GraphApi");
json = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();
}
catch (Exception ex)when(ex is MsalUiRequiredException || ex is MicrosoftIdentityWebChallengeUserException)
{
ConsentHandler.HandleException(ex);
}
catch (Exception ex)
{
json = ex.Message + "\r\n" + json;
StateHasChanged();
}
}
How are you authenticating? If using the client credentials flow, there is no logged in user, hence you cannot user /me. Use /user/{userId}/mailboxSettings instead.
Graph explorer uses delegate permissions, /me works fine therein.
Hello Julien Marpault,
Thank you for reaching out to Microsoft Support!
Please check whether your account lacks MS 365 License, as shown below:
You can refer to this case:
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.