Graph API: Filter Teams Export API by channel ID

David Proctor 21 Reputation points
2022-11-17T19:09:56.003+00:00

I am trying to use the Graph API's Teams Export API to export all messages in a single Teams channel. I know that my permissions are set up correctly - if I request GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages, I get a list of every message in every channel in the team. The linked documentation also includes a sample request that uses $filter to get results with a lastModifiedDateTime between two limits; I get the expected results from calling something like this.

The obvious approach is to request https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=channelIdentity/channelId eq '{CHANNEL_ID}'. This returns the following error:

{  
  "error": {  
    "code": "BadRequest",  
    "message": "The entity property 'channelIdentity/channelId' and operationKind 'Equal' is not allowed in $filter query.",  
    "innerError": {  
      "date": "2022-11-17T18:27:18",  
      "request-id": "...",  
      "client-request-id": "..."  
    }  
  }  

What I'm gathering here is that we can't run an equality operation on this field. Is there some kind of documentation specifying which operations are allowed on which fields?

I also tried using startswith instead. GET https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/getAllMessages?$filter=startswith(channelIdentity/channelId, '{TRUNCATED CHANNEL ID}') returns this error:

{  
  "error": {  
    "code": "BadRequest",  
    "message": "Only binary operation expressions are allowed.",  
    "innerError": {  
      "date": "2022-11-17T18:38:05",  
      "request-id": "...",  
      "client-request-id": "..."  
    }  
  }  
}  

I have no idea what this error message is trying to tell me. As I read it, a "binary operation expression" should resolve to a boolean result on each candidate; I don't see why that wouldn't work with this query.

My primary question is, how do I return only results from a single channel from the Teams Export API? Is it even possible to do so using $filter?

Another strange behavior I noticed: the sample query on the documentation gets the top 50 results between two lastModifiedDateTimes: GET https://graph.microsoft.com/v1.0/teams/{id}/channels/getAllMessages?$top=50&$filter=lastModifiedDateTime gt 2020-06-04T18:03:11.591Z and lastModifiedDateTime lt 2020-06-05T21:00:09.413Z. This works as expected. If I remove one of the date limits, though, I get an error: GET https://graph.microsoft.com/v1.0/teams/{id}/channels/getAllMessages?$top=50&$filter=lastModifiedDateTime gt 2020-06-04T18:03:11.591Z returns "message": "Invalid $filter query.". What is invalid about this filter?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,430 questions
0 comments No comments
{count} votes

Accepted answer
  1. Gopinath Chennamadhavuni 2,431 Reputation points
    2022-11-18T06:16:26.857+00:00

    Hi @David Proctor ,

    Thanks for reaching out.

    Graph API which you are referring to retrieve messages of channel in a team, only support the listed query parameters, as per this documentation $filter is supported with dateTime range query on lastModifiedDateTime.
    Retrieve the list of messages (without the replies) in a channel of a team, please use the graph API: GET /teams/{team-id}/channels/{channel-id}/messages, refer this documentation for more details.

    To get the replies for a message, call the list message replies or the get message reply API.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

0 additional answers

Sort by: Most helpful