Microsoft Graph API and events start and end dates

Anonymous
2022-10-26T07:11:36.6+00:00

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:

254256-outlook-event.png

and

254208-outlook-event-0.png

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?

Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-10-26T11:37:08.203+00:00

    I forgot to add the header:

       var events = await _graphServiceClient.Users[emailAddress]  
           .Events  
           .Request()  
           .Header("Prefer","outlook.timezone=\"W. Europe Standard Time\"")  
           .GetAsync();  
    

Your answer

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