Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
grumpyp opened this issue Oct 10, 2024 · 1 comment
Assignees
Labels
type:bug A broken experience

Comments

@grumpyp
Copy link

grumpyp commented Oct 10, 2024

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 grumpyp added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Oct 10, 2024
@shemogumbe
Copy link
Collaborator

Hello @grumpyp thanks for using the SDK and for raising this.

Yes, start date and end_date are not valid for the CalendarViewRequestBuilder, https://github.com/microsoftgraph/msgraph-sdk-python/blob/main/msgraph/generated/solutions/booking_businesses/item/calendar_view/calendar_view_request_builder.py

The appropriate keys for your use case would be start and end

Your code with the adjustment below works perfectly for me:

query_params = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetQueryParameters(
    start=start_date_str,
    end=end_date_str,
    select=['subject', 'start', 'end'],
    top=100,
    orderby=['start/dateTime ASC'],
    #filter="contains(subject, 'from HR Works')"
)

@shemogumbe shemogumbe added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Oct 16, 2024
@grumpyp grumpyp closed this as completed Oct 16, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants