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

Unable to filter the outlook calendar data with specific time duration #3198

Open
bhoomesh-spe opened this issue Jan 27, 2025 · 1 comment
Open

Comments

@bhoomesh-spe
Copy link

What version of PnPjs library you are using

3.x (No longer supported)

Minor Version Number

3.15.0

Target environment

All

Additional environment details

"@microsoft/sp-core-library": "1.17.1",
"@microsoft/sp-lodash-subset": "1.17.1",
"@microsoft/sp-office-ui-fabric-core": "1.17.1",
"@microsoft/sp-property-pane": "1.17.1",
"@microsoft/sp-webpart-base": "1.17.1",
"@pnp/graph": "^3.15.0",
"@pnp/logging": "^3.15.0",
"@pnp/queryable": "^3.15.0",
"@pnp/sp": "^3.15.0",

Question/Request

Hello Everyone,

I created the SPFx react project and used the PnP library for that project.
I need to get data from the Outlook calendar.

I have tried the query below as suggested on the official PnP site.
const view4 = await graph.me.calendarView("2025-01-01", "2025-01-31")();

Please refer to the below link for the official site.
https://pnp.github.io/pnpjs/graph/calendars/#get-calendar-view

I have implemented the below code to get events for a specific span.

import { GraphFI } from '@pnp/graph';
import '@pnp/graph/calendars';
import "@pnp/graph/presets/all";
import { InjectHeaders } from "@pnp/queryable";
 
export const getCurrentMonthCalendarsData = async () => {
    const graph: GraphFI = getGraph();
    try {
        const allEvents = [];
        const startDateTime = "2025-01-01T00:00:00Z"
        const endDateTime = "2025-01-31T23:59:59Z"
        const currentUserMailBoxTimeZone = (await graph.me.mailboxSettings()).timeZone;
        let events = await graph.me.calendarView(startDateTime, endDateTime).expand(...["instances"]).using(InjectHeaders({
            'Prefer': 'outlook.timezone="' + currentUserMailBoxTimeZone + '"'
        })).top(999).paged();
        allEvents.push(...events.value);
 
        while (events && events.hasNext) {
            events = await events.next();
            allEvents.push(...events.value);
        }
 
        return allEvents;
    } catch (ex) {
        throw ex;
    }
};

The above code has thrown me a below error.

{
    "error": {
        "code": "ErrorInvalidParameter",
        "message": "This request requires a time window specified by the query string parameters StartDateTime and EndDateTime."
    }
}

Can anyone help me with the same?

Thanks in Advance.

@patrick-rodgers
Copy link
Member

I think you've recreated this issue again: #3136

We fixed it in v4 here. V3 is no longer supported, so you could update to v4 to get the fix, or use a custom behavior for paging to handle this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants