msgraph-sdk-python icon indicating copy to clipboard operation
msgraph-sdk-python copied to clipboard

CalendarViewRequestBuilder - query parameter for start_date_time and end_date_time don't work

Open grumpyp opened this issue 1 year ago • 0 comments

Describe the bug

Linking to my StackOverflow question:

https://stackoverflow.com/questions/79070227/calendarviewrequestbuilder-msgraph-python-sdk-query-parameter-for-start-da

Expected behavior

returning events in the specified date range

How to reproduce

# 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)
...

SDK Version

1.9.0

Latest version known to work for scenario above?

No response

Known Workarounds

Usage of the API via Graph Explorer works.

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

grumpyp avatar Oct 10 '24 06:10 grumpyp