Search code examples
c#azureazure-active-directorymicrosoft-graph-apimicrosoft-graph-teams

Microsoft.Graph.Models.ODataErrors.ODataError when doing Get Request to Microsoft Graph API


Do not know how to solve the problem below

I cannot get a response from Microsoft Graph API. API works with some other requests. I was following instructions from these pages https://learn.microsoft.com/en-us/graph/tutorials/dotnet-app-only?tabs=aad but cannot make my own requests.

App permissions that are given and confirmed by admin:

  • Application.Read.All
  • Chat.Read.All
  • Chat.ReadBasic.All
  • Chat.ReadWrite.All
  • Group.Read.All
  • User.Read.All

I get ids of users with:

_ = _appClient ??
            throw new System.NullReferenceException("Graph has not been initialized for app-only auth");
var response = await _appClient.Users.GetAsync();

There are no exceptions, everything works (as I understand it must work). And then try to get all the chats from Microft Teams of the user using his id:

var response = await _appClient.Users[id].Chats.GetAsync();

Exception message and Stack Trace


Solution

  • I figured out what type of error it was with the help of ODataError class:

    try
    {
          var response = await _userClient.Me.Chats.GetAsync();
          return response;
    }catch (ODataError er)
    {
          Console.WriteLine(er.Error.Code);
          Console.WriteLine(er.Error.Message);
          return null;
    }
    

    Thanks)