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

Get recurring events with paging throws an error that query string parameters StartDateTime and EndDateTime are required. #3136

Open
bhoomesh-spe opened this issue Sep 20, 2024 · 3 comments

Comments

@bhoomesh-spe
Copy link

What version of PnPjs library you are using

3.x

Minor Version Number

3.15.0

Target environment

SharePoint Framework

Additional environment details

SharePoint Online, SPFx React

Question/Request

Hello Everyone,

I have implemented the below code to get the current user outlook event using PnP Graph API in the SPFx React project.

export const getCalendarsData = async () => {
  const graph: GraphFI = getGraph();
  try {
    const events = await graph.me.events.paged();
    return events;
  } catch (ex) {
    throw ex;
  }
}

Currently I got the current logged in user's outlook event as expected.

But the event start time and end time is in the UTC time zone. I will need the same in the current user local time zone.

I have checked and found that I need to add something like the below in my PnP Graph API call to get the current user events from Outlook.

"Prefer":outlook.timezone="Pacific Standard Time"

How can I pass the Prefer to my PnP Graph API call?

Can anyone help with the same?

Thanks

@juliemturner
Copy link
Collaborator

Did you try: https://pnp.github.io/pnpjs/queryable/behaviors/#injectheaders

@bhoomesh-spe
Copy link
Author

@juliemturner - Thanks for the response.

I have implemented as you had suggested and it is working as expected. Thanks for the same.

Now, I have faced one issue when I tried to get recurring events it threw me the below error.
This request requires a time window specified by the query string parameters StartDateTime and EndDateTime.

Please check the code snippet for more clarification.

export const getAllRecurringEventInstances = async (currentUserMailBoxTimeZone, event) => {
    const graph: GraphFI = getGraph();
    const allEvents = [];
    const startDateTime = event?.recurrence?.range?.startDate + "T" + event?.start.dateTime.split('T')[1];
    const endDateTime = event?.recurrence?.range?.endDate + "T" + event?.end.dateTime.split('T')[1];
    let events = await graph.me.events.getById(event.id).instances(startDateTime, endDateTime).using(InjectHeaders({
        'Prefer': 'outlook.timezone="' + currentUserMailBoxTimeZone + '"'
    })).top(999).paged();
    allEvents.push(...events.value);
 
    while (events.hasNext) {
        events = await events.next();
        allEvents.push(...events.value);
    }
 
    return allEvents;
};

Can you please help me on the same?

Thanks

@patrick-rodgers
Copy link
Member

@bhoomesh-spe - can you do a quick test without the paged() and see if it works as expected?

This looks like we are stripping those params when we create the paged collection.

@juliemturner juliemturner changed the title How to get event timezone same as current user timezone instead of UTC Get recurring events with paging throws an error that query string parameters StartDateTime and EndDateTime are required. Sep 23, 2024
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

3 participants