Is there any way to query to see if a user
exists in microsoft graph without an exception being thrown (i will be querying by id). For example i could do the following:
using Azure.Identity;
using System;
using System.Threading.Tasks;
public class GraphApiService
{
private readonly GraphServiceClient _graphServiceClient;
public GraphApiService(string tenantId, string clientId, string clientSecret)
{
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
_graphServiceClient = new GraphServiceClient(credential, new[] { "https://graph.microsoft.com/.default" });
}
public async Task<User> GetUserByIdAsync(string userId)
{
try
{
var user = await _graphServiceClient.Users[userId].Request().GetAsync();
return user;
}
catch (ServiceException ex)
{
Console.WriteLine($"Error getting user: {ex.Message}");
throw;
}
}
}
but I would much prefer a way that doesn’t throw an exception.