Skip to content

Microsoft Graph Api Integration issue #2889

Open
@abdullahakm

Description

@abdullahakm

We want to use Microsoft Graph Api (Outlook.Calendar this Api endpoint : https://graph.microsoft.com/v1.0/me/events?$select=subject,body,bodyPreview,organizer,attendees,start,end,location) with all the required configuration related to azure.
The below is our console app code, in future we move our console app to Background Service
try
{
var credential = new ClientSecretCredential(TenantId, ClientId, ClientSecret);

    var authProvider = new AzureIdentityAuthenticationProvider(
        credential,
        scopes: ["https://graph.microsoft.com/.default"],
        isCaeEnabled: false 
    );

    var graphClient = new GraphServiceClient(authProvider);

    string userIdentifier = "our user identity";

    var events = await graphClient.Users[userIdentifier].Events
        .GetAsync(requestConfig =>
        {
            requestConfig.QueryParameters.Select = new[] {
                "subject", "bodyPreview", "organizer", "start", "end", "location"
            };
            requestConfig.QueryParameters.Top = 10;
        });

    Console.WriteLine($"Success! Found {events?.Value?.Count ?? 0} events.");
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex.Message}");
    Console.WriteLine($"Details: {ex.InnerException?.Message}");
    Console.WriteLine("TIP: Check permissions, user ID format, and try disabling CAE");
}

}

This error is occurred : Microsoft.Kiota.Abstractions.ApiException: 'The server returned an unexpected status code and the error registered for this code failed to deserialize: 401'.

Can anyone have idea of this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions