Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs
GetAllMessages API is not supported in delegated Context. If you are using Application permissions to get all the messages across all chats, it requires additional validation as this particular API comes under Protected APIs. To request access for this protected API, you need to submit the request and get approval.
Documentation reference- https://learn.microsoft.com/en-us/graph/teams-protected-apis
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment"