Problem with GraphServiceClient getting chat objects from Teams

Brandon Poindexter 71 Reputation points
2023-06-21T15:34:19.32+00:00

I have this code running iteratively in a loop to gather chat objects associated with each Azure user in our tenant:

var nextPageRequest = new ChatsRequestBuilder(nextPageLink, appClient.RequestAdapter);

chatPage = await nextPageRequest.GetAsync();

In the above code, appClient is the GraphServiceClient object.

Sometimes, this request fails, but not in any pattern I can discern. The error I usually get first is simply 'UnknownError' and the error code is 502 Bad Gateway. Subsequent calls with this same line of code generates a different error: PreconditionFailed. Requested API is not support in an application-only context.

This does not always occur in my loop, but it usually does. My initial presumption is that I'm being rate limited, however I don't have any direct evidence of that. If that's the case, then once rate limiting kicks in, the subsequent error would suggest that my authentication was revoked as part of that rate limiting.

My understanding is that the GraphServiceClient is supposed to deal with rate limiting without any input from me, but if that's not the case, then how would I go about detecting when I'm about to be rate limited?

Microsoft Teams | Development
Microsoft Teams | Development
Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs
Microsoft Security | Microsoft Graph
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Sayali-MSFT 4,686 Reputation points Microsoft External Staff Moderator
    2023-06-26T09:36:02.1566667+00:00

    @@Brandon Poindexter - Please refer this documentation to know about Microsoft Teams Service API rate limits.

    As your error message says, send messages does not support application-only context for the time being, it currently only supports user context.

    197135-2022-04-28-103113.png


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.