Search code examples
microsoft-graph-apimicrosoft-graph-sdks

App only C# code, does not work like the Graph explorer


In graph explorer:

https://graph.microsoft.com/v1.0/teams/aebabbef-180f-49f6-92c9-be4201be286d/channels/19:6fe6827cc59d48558a21e7c6df64caec@thread.tacv2/messages 

works fine I get a json with data.

The code snippets shows:

var messages = await graphClient.Teams["aebabbef-180f-49f6-92c9-be4201be286d"].Channels["19:6fe6827cc59d48558a21e7c6df64caec@thread.tacv2"].Messages
.Request()
.GetAsync();

So I use it as is in a console application With app only permission that has all the graph permissions but I get the error:

Code: UnknownError
Inner error:
        AdditionalData:
        date: 2021-01-24T20:03:02
        request-id: 9c294c0c-328a-4ca4-bcd0-1cbb3999dfd7
        client-request-id: 9c294c0c-328a-4ca4-bcd0-1cbb3999dfd7
ClientRequestId: 9c294c0c-328a-4ca4-bcd0-1cbb3999dfd7

anyone know what the error can be?

Thanks


Solution

  • This is because the List Channel Messages endpoint doesn't support App only permissions as shown below. Please check the documentation here. It works on the Graph Explorer because it gets the user token there.

    enter image description here