Microsoft.Graph.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.

Angelica 10 Reputation points
2023-07-12T13:29:16.1833333+00:00

Good afternoon Community,

I am having an issue when querying Graph API from a console app as it keeps giving me the following error when a very simple odata query is built:

Error trying to query ADD data Microsoft.Graph.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.Users.UsersRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken)

The query works perfectly when I execute the console app locally on my laptop but now that I am migrating this little console app into an Azure virtual machine, then the communication to Graph API is generating the errors mentioned above.

I am running out of ideas, does anyone know what can I do here, please? Many thanks in advance.

Please see below the API permissions

User's image

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,006 questions
{count} votes

6 answers

Sort by: Most helpful
  1. Angelica 10 Reputation points
    2023-07-13T10:40:23.2266667+00:00

    Thank you very much for your assistance.

    This issue has now been resolved, but I am going to give a bit more of context just in case someone else finds it useful.

    This application is a console app, this console app was working fine on my local dev machine, however, when I deployed the app on an Azure VM, the queries to Graph API stopped working and it was giving me the error I described in my question.

    So I had the suspicion this was down to configuration within the Azure portal than anything else inside the code (as the app was working correctly on the development machine using my account as Managed identity), so one of the infrastructure engineers helped me replicating the permissions of the VM to access Graph API

    User's image

    And after 15 minutes, it all worked well again. In summary the system managed identity of the VM had to replicate the same API permissions that my app had in order to work well on it.

    Thanks again for your help and I hope this can help someone else having this issue as the error message is completely misleading!

    Angelica

    2 people found this answer helpful.

  2. TH-4749-MSFT 3,360 Reputation points
    2023-07-12T15:56:13.67+00:00

    Hello Angelica,

    Thanks for reaching out. To assist you better please provide the Graph query you are experiencing the issue with.

    Thanks.

    0 comments No comments

  3. TH-4749-MSFT 3,360 Reputation points
    2023-07-12T15:59:37.07+00:00

    Hello Angelica,

    Thanks for reaching out. To assist you better please provide the query you are experiencing the issue with.

    Thanks.

    0 comments No comments

  4. TH-4749-MSFT 3,360 Reputation points
    2023-07-12T16:02:04.6833333+00:00

    Hello Angelica,

    Thanks for reaching out. To assist you better please provide the query you are experiencing the issue with.

    Thanks.

    0 comments No comments

  5. TH-4749-MSFT 3,360 Reputation points
    2023-07-12T16:06:55.78+00:00

    Hello Angelica,

    Thanks for reaching out. To assist you better please provide the query you are experiencing the issue with.

    Thanks.

    0 comments No comments