google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

How to retrieve recurring all day events

Open jreimone opened this issue 1 year ago • 7 comments

I use the calendar API in TypeScript and want to retrieve all all-day events of a certain day. The problem is that I only receive non all-day events. This is what I tried:

import {GoogleAuth, JWT} from "google-auth-library";
import {calendar_v3} from "@googleapis/calendar";
import Calendar = calendar_v3.Calendar;

describe("How Google Calendar API can be used", () => {

    const calendarID = "myCalendarID";

    let calendarApi: Calendar;

    beforeEach(async () => {
        const scopes = [
            'https://www.googleapis.com/auth/calendar.events', // required for reading all details and writing into calendar
            'https://www.googleapis.com/auth/calendar.readonly',
        ];
        const auth = new GoogleAuth({
            scopes: scopes,
        });
        const envVar = process.env['JWT_AUTH_TOKEN'];
        // @ts-ignore
        const tokenKeyValues = JSON.parse(envVar);
        // @ts-ignore
        const authClient: JWT = auth.fromJSON(tokenKeyValues);
        calendarApi = new Calendar({
            auth: authClient
        });
        expect(calendarApi).not.toBeNull();
        expect(calendarApi).not.toBeUndefined();
    });

    it('should retrieve all-day events of today', async () => {
        const startOfToday = new Date();
        startOfToday.setHours(0, 0, 0);
        const endOfToday = new Date();
        endOfToday.setHours(23, 59, 59);

        const eventsOfToday = await calendarApi.events.list({
            calendarId: calendarID,
            timeMin: startOfToday.toISOString(),
            timeMax: endOfToday.toISOString(),
            singleEvents: true
        });
        const events = eventsOfToday.data.items;
        expect(events).not.toBeUndefined();

        // @ts-ignore
        for (let event of events) {
            console.log(event);
        }
    });
});

It only return those events not being all-day events. Maybe worth to mention that the all-day events are also recurring events. I don't know if it's important? How can I achieve this?

jreimone avatar Mar 06 '23 12:03 jreimone

Hi @jreimone in taking a look at the API documentation it is likely you need to modify or remove the timeMin and timeMax parameters. I believe they are likely filtering out all day events.

ddelgrosso1 avatar Mar 06 '23 16:03 ddelgrosso1

@ddelgrosso1 but how could I ask then for all-day events of a particular day?

jreimone avatar Mar 06 '23 16:03 jreimone

Both timeMin and timeMax are exclusive. I believe you will need to adjust accordingly.

ddelgrosso1 avatar Mar 06 '23 19:03 ddelgrosso1

@jreimone were you able to resolve this?

ddelgrosso1 avatar Mar 10 '23 17:03 ddelgrosso1

Unfortunately not, I don't get recurring all-day events. Thought this is covered by singleEvents: true but doesn't work.

jreimone avatar Mar 13 '23 07:03 jreimone

@jreimone any updates on this issue?

ddelgrosso1 avatar Aug 31 '23 14:08 ddelgrosso1

Unfortunately not, I stopped trying due to other priorities.

jreimone avatar Aug 31 '23 18:08 jreimone