Sort Events by Start Date
Asked Answered
F

1

13

I need to be able to get the events in both directions ASC/DESC using Microsoft Graph API. I'm trying the following API to achieve that:

https://graph.microsoft.com/v1.0/me/events?$orderby=start

However, when I perform the request I get the following error:

{
    "error": {
        "code": "BadRequest",
        "message": "The $orderby expression must evaluate to a single value of primitive type.",
        "innerError": {
            "request-id": "c00d676d-ef8e-418b-8561-80e08729da71",
            "date": "2017-11-16T13:31:59"
        }
    }
}

Also, I tried to access the date directly:

https://graph.microsoft.com/v1.0/me/events?$orderby=start.dateTime

Got the following error:

{
    "error": {
        "code": "BadRequest",
        "message": "The child type 'start.dateTime' in a cast was not an entity type. Casts can only be performed on entity types.",
        "innerError": {
            "request-id": "240342f5-d7f6-430b-9bd0-190dc3e1f73b",
            "date": "2017-11-16T13:32:39"
        }
    }
}

Is there a way to sort events by date in ASC/DESC order?

Florettaflorette answered 16/11, 2017 at 13:35 Comment(0)
S
19

You're very close but you're referencing DateTime incorrectly. The proper format is {parent}/{child}. These will work:

https://graph.microsoft.com/v1.0/me/events?$orderby=start/dateTime
https://graph.microsoft.com/v1.0/me/events?$orderby=start/dateTime desc
Stabler answered 16/11, 2017 at 13:59 Comment(2)
It's exactly what I need. Thanks!Florettaflorette
here is the link to the official documentation. It shows an example how to access complex objects with this / notation mentioned here. learn.microsoft.com/en-us/graph/…Devora

© 2022 - 2024 — McMap. All rights reserved.