I am using Graph
client to get details and here is the code
var signIns = await graphClient
.AuditLogs
.SignIns
.Filter($"UserPrincipalName eq '{UserPrincipalName}' and IsInteractive eq true and status/errorCode eq 0").OrderBy("CreatedDateTime")
.GetAsync();
Packages Used:
Microsoft.Graph
5.56 version
I am getting below error
'SignInsRequestBuilder' does not contain a definition for 'Filter' and no accessible extension method 'Filter' accepting a first argument of type 'SignInsRequestBuilder' could be found
I have tried many different Microsoft.Graph
versions but unable to resolve it?
To fetch the SignInLogs, modify the code like below:
Code snippet work for the latest version. Current version is 5.x
namespace GraphApiExample
{
class Program
{
static async Task Main(string[] args)
{
var clientId = "ClientID";
var tenantId = "TenantID";
var clientSecret = "Secret";
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential);
var userPrincipalName = "rukuser@XXX.onmicrosoft.com";
// Query sign-in logs with filtering and ordering
var result = await graphClient.AuditLogs.SignIns.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Filter = $"UserPrincipalName eq '{userPrincipalName}' and isInteractive eq true and status/errorCode eq 0";
requestConfiguration.QueryParameters.Orderby = new string[] { "createdDateTime" };
});
if (result?.Value != null)
{
foreach (var signIn in result.Value)
{
Console.WriteLine($"Sign-in ID: {signIn.Id}, UPN: {signIn.UserPrincipalName}, Date: {signIn.CreatedDateTime}");
}
}
else
{
Console.WriteLine("No sign-ins found.");
}
}
}
}