google-api-nodejs-client
google-api-nodejs-client copied to clipboard
How to retrieve recurring all day events
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?
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 but how could I ask then for all-day events of a particular day?
Both timeMin
and timeMax
are exclusive. I believe you will need to adjust accordingly.
@jreimone were you able to resolve this?
Unfortunately not, I don't get recurring all-day events. Thought this is covered by singleEvents: true
but doesn't work.
@jreimone any updates on this issue?
Unfortunately not, I stopped trying due to other priorities.