Sorting by createdDateTime with Graph API returns unsupportedQuery

Jirayu Methathip 5 Reputation points
2023-12-26T09:25:54.2866667+00:00

Hello,

I am attempting to query users using pagination, sorting by createdDateTime in descending order. According to the official documentation for Graph API, sorting using advanced query parameters should be supported. However, despite including the necessary parameters in the request, I am still receiving the following error message in the response:

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported sort property 'createdDateTime' for 'User'.",
        "innerError": {
            "date": "2023-12-26T09:17:14",
            "request-id": "01ad7d5e-c76f-4c07-a66d-dcbb71ebf674",
            "client-request-id": "01ad7d5e-c76f-4c07-a66d-dcbb71ebf674"
        }
    }
}

And this is the request (in curl)

curl --location 'https://graph.microsoft.com/v1.0/users?%24select=identities%2CbusinessPhones%2CdisplayName%2CgivenName%2CjobTitle%2Cmail%2CmobilePhone%2CpreferredLanguage%2Csurname%2CuserPrincipalName%2Cid%2CcreatedDateTime&%24orderby=createdDateTime%20desc&%24count=true' \
--header 'ConsistencyLevel: eventual' \
--header 'Authorization: Bearer {{token}}'

Does anyone have any suggestions or experience with this issue? Thank you in advance for your help!

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

2 answers

Sort by: Most helpful
  1. Diah.Karim-MSFT 335 Reputation points Microsoft External Staff
    2023-12-27T02:12:07.4733333+00:00

    Hi Jirayu..

    I think the above endpoint been called with incorrect value (the $count=true should come before the $orderby)

    i have tested with below endpoint and its works. And i'm using the Graph Explorer to test it.

    https://graph.microsoft.com/v1.0/users?$select=identities,businessPhones,displayName,givenName,jobTitle,mai,mobilePhone,preferredLanguage,surName,userPrincipalName,id,createdDateTime&$count=true&$orderby=createdDateTime desc

    Hope this helps.

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


  2. CarlZhao-MSFT 46,351 Reputation points
    2023-12-27T03:04:35.72+00:00

    I just did a quick test using Graph Explorer and it seems to be working fine. So I'm sure using the createdDateTime parameter to sort user sets is supported in advanced queries.

    57d1e556-a919-4658-a095-a9c3b6e162d2


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.