Home > Software engineering >  NotAcceptable error when calling graph API from C#
NotAcceptable error when calling graph API from C#

Time:09-12

Hey guys i'm trying to get a list of all rooms in a tenant but i'm receiving an error I see no solution to. My graph service client appears to be correct since I can get a list of all users without issues, but getting all the rooms fails with an unknown error.

What i'm trying to replicate: Azure ad app permissions

Error code:

      An unhandled exception has occurred while executing the request.
      Status Code: NotAcceptable
      Microsoft.Graph.ServiceException: Code: UnknownError
      Inner error:
        AdditionalData:
        date: 2022-09-11T12:06:02
        request-id: 1d5d8c56-235c-452d-aa2c-9d71cbf2d7a9
        client-request-id: 1d5d8c56-235c-452d-aa2c-9d71cbf2d7a9
      ClientRequestId: 1d5d8c56-235c-452d-aa2c-9d71cbf2d7a9

         at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
         at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
         at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
         at Microsoft.Graph.GraphServicePlacesCollectionRequest.GetAsync(CancellationToken cancellationToken)
         at PicoWebAPI.Controllers.MeetingsController.Get() in C:\Users\Blue\source\repos\MeetingRoomBooking\PicoWebAPI\Controllers\MeetingsController.cs:line 25
         at lambda_method5(Closure , Object )
         at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
         at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

CodePudding user response:

Let's see the api response via enter image description here enter image description here

So in this scenario, request https://graph.microsoft.com/v1.0/places equals to SDK await graphClient.Places.Request().GetAsync(); which should met this error. And this is because Graph SDK does not currently support filtering by derived types which is a known issue. A enter image description here

CodePudding user response:

could you please follow the docs for setting up clientCredentailflow - https://docs.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS#client-credentials-provider

ref doc - https://docs.microsoft.com/en-us/dotnet/api/azure.identity.clientsecretcredential.-ctor?view=azure-dotnet#azure-identity-clientsecretcredential-ctor(system-string-system-string-system-string-azure-identity-clientsecretcredentialoptions) [![enter image description here][1]][1]

  • Related