Graph API's filtering capabilities that allows messages to be retrieved only from the desired channel

ponthijr 0 Reputation points
2023-10-05T10:22:48.0833333+00:00

I am looking into how to grant Microsoft Graph access to retrieve specific channel information in Microsoft Teams.We are looking at ways to restrict access to specific channels. By default, I believe the (Team.ReadBasic.All, Channel.readBasic.All,ChannelMessage.Read.All) permission provides access to all channel messages. However, if we want to restrict access to specific channels, I have heard that this can be accomplished by requiring additional logic to be implemented within the application. Is there any way to filter the Graph API? to retrieve only messages from the required channels. Please tell me the specific command to use the filtering function using Graph API PowerShell.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,445 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,065 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ChetanSharmamsft 1,026 Reputation points Microsoft Vendor
    2023-10-06T07:10:14.1933333+00:00

    Hello @ponthijr - You can use below command to get specific channel messages:
    Import-Module Microsoft.Graph.Teams

    Get-MgTeamChannelMessage -TeamId $teamId -ChannelId $channelId -Top 3

    Reference doc: https://learn.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-1.0&tabs=powershell#example-1-request-with-top-query-parameter-and-without-optional-prefer-header

    Please let me know if you need further assistance here.