How are the chat messages sorted when using GraphAPI?

Hg 0 Reputation points
2024-09-10T02:43:22.4766667+00:00

I’m using the Microsoft Graph API to list channel messages, following this documentation: Channel List Messages. I'm using the $top parameter to retrieve 50 messages at a time. I've noticed that the messages are consistently sorted by lastModifiedDateTime, but I couldn’t find any documentation that explicitly states whether the $top parameter enforces this sorting or if it's the default behaviour of the API. Could you clarify if the sorting is intrinsic to the API or controlled by the query?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,088 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,005 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rohit Raghuwanshi - MSFT 470 Reputation points Microsoft Vendor
    2024-09-10T08:51:59.04+00:00

    Hi Hg,

    Thank you for reaching out, Microsoft!

    I attempted to retrieve channel messages without any OData query parameters, such as the $top parameter, and noticed that the messages are still ordered by lastModifiedDateTime . This implies that lastModifiedDateTime is the default ordering, even though there is no explicit documentation stating that the List Channel Messages API returns responses in this order. The List Chat Messages API documentation does mention that lastModifiedDateTime is the default order in which messages are returned in the response.

    Also please refer below doc which mentions only $top and $expand are Optional query parameters supported by List Channel Messages and it does not support explicit ordering.

    https://learn.microsoft.com/en-us/graph/api/channel-list-messages?view=graph-rest-1.0&tabs=http#optional-query-parameters

    Please check attached screenshot for reference:

    User's image

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

    0 comments No comments

  2. Yakun Huang-MSFT 4,640 Reputation points Microsoft Vendor
    2024-09-10T09:45:41.3433333+00:00

    Hi @Hg

    According to the documentation, there are instructions for ordering the messages that come back accordingly.

    User's image

    It is sorted in descending order according to the lastModifiedDateTime parameter, which is the default sort.

    Hope this helps.

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


Your answer

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