skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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)


  2. @SergioMartin, Yes, the exception is misleading, you need to check the InnerException why you got into this state. Catch the exception on the call and check the inner exception. It could be a different reason. Also check the token with

    https://jwt.ms/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search