Reputation: 2860
I am working with the Graph API and trying to create events using the C# Microsoft.Graph
API. Let's assume to have the following Microsoft.Graph.Event
objects:
{
Subject = "A Title",
Body = new ItemBody(),
Start = {
DateTime = "2022-10-24T00:00:00",
TimeZone = "W. Europe Standard Time"
},
End ={
DateTime = "2022-10-25T00:00:00",
TimeZone = "W. Europe Standard Time"
},
IsAllDay = true,
},{
Subject = "B Title",
Body = new ItemBody(),
Start = new DateTimeTimeZone {
DateTime = "2022-10-28T13:30:00",
TimeZone = "W. Europe Standard Time"
},
End = new DateTimeTimeZone {
DateTime = "2022-10-28T16:45:00",
TimeZone = "W. Europe Standard Time"
},
IsAllDay = false,
}
They are successfully written into my calendar trough twice call to:
await _graphServiceClient.Users[emailAddress].Events.Request().AddAsync(graphEvent);
and I see:
and
which is the expected behaviour.
Querying the API with the filter "start/dateTime ge '2022-10-24T00:00:00'"
I get just B Title
, A Title
is missing. Furthermore the start and end dates are wrong, I get 2022-10-28T11:30:00.0000000
and 2022-10-28T14:45:00.0000000
.
If I edit the query to "start/dateTime ge '2022-10-23T00:00:00'"
I get both, the dates of B title
are the same (wrong), but the ones of A Title
ar correct 2022-10-24T00:00:00.0000000
and 2022-10-25T00:00:00.0000000
.
I expected that B Title
has 2022-10-28T13:30:00.0000000
and 2022-10-28T16:45:00.0000000
. What am I doing wrong?
Upvotes: 0
Views: 1568
Reputation: 20660
When you call list events endpoint you can specify request header Prefer: outlook.timezone="<time-zone>"
. If not specified, those time values are returned in UTC.
Example:
var events = await _graphServiceClient.Users[emailAddress]
.Events
.Request()
.Header("Prefer","outlook.timezone=\"W. Europe Standard Time\"")
.GetAsync();
I guess that with the correct outlook.timezone
header your query will return also A Title
and correct time values.
References:
Calendar list events - request headers
Upvotes: 1