Hi @SAC_535
You can call the endpoint using the C# Graph SDK, and since /users/{user id}
only supports application contexts, you need to use the client credentials flow to get a token. Please refer to the complete code:
using Azure.Identity;
using Microsoft.Graph;
using Newtonsoft.Json;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "{tenant id}";
// Values from app registration
var clientId = " {client id}";
var clientSecret = "{client secret}";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var message = await graphClient.Users["{user id}"].Messages["{message id}"]
.Request()
.GetAsync();
Console.WriteLine("message:" + JsonConvert.SerializeObject(message));
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.