I've been playing around with the start_date_time
and the end_date_time
like this:
# Create GraphServiceClient
graph_client = GraphServiceClient(credential, scopes)
# Define date range for fetching events
start_date = datetime.now(pytz.utc)
end_date = start_date + timedelta(days=365)
# Format dates correctly for the Graph API in ISO 8601 format
start_date_str = start_date.strftime("%Y-%m-%dT%H:%M:%S%z")
end_date_str = end_date.strftime("%Y-%m-%dT%H:%M:%S%z")
# Insert colon in timezone offset
start_date_str = start_date_str[:-2] + ":" + start_date_str[-2:]
end_date_str = end_date_str[:-2] + ":" + end_date_str[-2:]
print(f"Fetching events from {start_date_str} to {end_date_str}")
# Set up the request configuration with query parameters as a dictionary
query_params = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetQueryParameters(
start_date_time=start_date_str,
end_date_time=end_date_str,
select=['subject', 'start', 'end'],
top=100,
orderby=['start/dateTime ASC'],
#filter="contains(subject, 'from HR Works')"
)
headers = HeadersCollection()
headers.add("Prefer", 'outlook.timezone="Europe/Berlin"')
request_configuration = RequestConfiguration(
query_parameters=query_params,
headers=headers
)
all_events = []
try:
# Initial request
events_page = await graph_client.users.by_user_id(user_id).calendars.by_calendar_id(calendar_id).events.get(request_configuration=request_configuration)
...
It says then basically Fetching events from 2024-10-09T12:27:39+00:00 to 2025-10-09T12:27:39+00:00
but checking on them I see lot's of events from 2023?
for instance Absence from 2023-10-13T10:00:00.0000000 to 2023-10-13T11:00:00.0000000:
Where is my issue? I tried tweaking the timestamps, but nothing worked.
Also been diving into the official documentation which did not help: https://learn.microsoft.com/en-us/graph/sdks/create-requests?tabs=python#use-select-to-control-the-properties-returned
EDIT: Using this query
https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2023-06-14T00:00:00Z&endDateTime=2024-06-15T00:00:00Z
in the GraphExplorer works, - meaning endDateTime
and startDateTime
parameters
query_params = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetQueryParameters( start_date_time='2023-06-14T00:00:00Z', end_date_time='2024-06-15T00:00:00Z', select=['subject', 'start', 'end'], top=100, orderby=['start/dateTime ASC'], #filter="contains(subject, 'from HR Works')" )
those not work in my script.