We are working on enabling sorting of chats based on lastMessageSent on the chat (basically the same way it is sorted on Teams client). Other than that, the chats are by default sorted by your action on the chat.
Sorting chats
Looks like it's not possible to retrieve the list of chats sorted in any way, e.g.
GET https://graph.microsoft.com/v1.0/me/chats?$select=lastUpdatedDateTime&$orderby=lastUpdatedDateTime
returns these values, in this order:
"lastUpdatedDateTime": "2022-03-08T22:27:12.474Z",
"lastUpdatedDateTime": "2019-05-17T18:31:05.384Z",
"lastUpdatedDateTime": "2022-03-02T00:52:01.711Z",
"lastUpdatedDateTime": "2021-02-19T23:25:57.206Z",
"lastUpdatedDateTime": "2022-05-31T22:11:02.634Z",
"lastUpdatedDateTime": "2020-07-10T18:16:00.073Z",
"lastUpdatedDateTime": "2022-06-01T18:20:32.263Z",
"lastUpdatedDateTime": "2022-06-01T00:35:29.165Z",
"lastUpdatedDateTime": "2022-06-01T14:23:14.407Z",
"lastUpdatedDateTime": "2022-04-05T22:04:33.659Z",
"lastUpdatedDateTime": "2022-06-01T06:55:48.95Z",
"lastUpdatedDateTime": "2022-06-01T06:55:47.173Z",
"lastUpdatedDateTime": "2022-06-01T06:51:22.061Z",
"lastUpdatedDateTime": "2022-05-24T19:36:18.756Z",
"lastUpdatedDateTime": "2022-05-26T01:29:20.443Z",
"lastUpdatedDateTime": "2022-05-31T19:48:55.566Z",
"lastUpdatedDateTime": "2022-05-27T21:11:46.461Z",
"lastUpdatedDateTime": "2022-05-31T20:10:10.359Z",
"lastUpdatedDateTime": "2021-05-26T20:05:25.244Z",
"lastUpdatedDateTime": "2022-05-31T21:34:13.562Z",
I've tried also the beta endpoint, and sorting by other fields like topic
and chatType
, e.g.
GET https://graph.microsoft.com/v1.0/me/chats?$select=chatType&$orderBy=chatType
"chatType": "oneOnOne"
"chatType": "oneOnOne"
"chatType": "oneOnOne"
"chatType": "oneOnOne"
"chatType": "oneOnOne"
"chatType": "oneOnOne"
"chatType": "meeting"
"chatType": "oneOnOne"
"chatType": "meeting"
"chatType": "group"
"chatType": "meeting"
"chatType": "meeting"
"chatType": "meeting"
"chatType": "meeting"
"chatType": "oneOnOne"
"chatType": "meeting"
"chatType": "group"
"chatType": "meeting"
"chatType": "oneOnOne"
Other endpoints work fine, e.g. https://graph.microsoft.com/v1.0/me/calendars?$select=name&$orderBy=name asc
and https://graph.microsoft.com/v1.0/me/calendars?$select=name&$orderBy=name desc
return the expected order.
Microsoft Graph
2 answers
Sort by: Most helpful
-
Ramjot Singh 861 Reputation points Microsoft Employee
2022-06-01T21:10:23.377+00:00 -
Devis Lucato 1 Reputation point Microsoft Employee
2022-06-01T21:23:44.203+00:00 My bad, I assumed
lastUpdatedDateTime
represents the last message timestamp. If I wanted to sort chats by "the last message" I would have to expand each chat, and sort by a message timestamp property, howeverme/chats?$expand=messages
returns 400 Bad Request, perhaps because this is not supported?In any case, the sorting seems broken, e.g. see my examples, the list is not sorted as per
$orderby
request.