Filtering api responses

How to filter api responses based on date or status or any other fields? We need filter response from below endpoints.

/users/{userId}/webinars
/webinars/{webinarId}/registrants
/past_webinars/{webinarId}/participants

I’m going to assume you’re using a JavaScript back end here for hitting these three endpoints. For all three, you can make use of simple array filtering.

For filtering the webinars, get the array object returned from response.data.webinars and filter it; you can use a library called date-fns to do some complex date-time tasks:

import { parseISO, isAfter, isBefore, startOfDay, endOfDay } from 'date-fns';
const items = response.data.webinars;
const date1 = startOfDay(new Date('2025-04-15'));
const date2 = endOfDay(new Date('2025-04-16'));
const filtered = items.filter(item => {
const time = parseISO(item.start_time);
return isAfter(time, date1) && isBefore(time, date2);
});

Note that you’ll want to make sure that your start/end dates and the webinar start_time are in the same time zone, for accuracy, which is a simple ask for date-fns. Your best bet is to make sure everything’s cast to UTC.

For filtering the participants, do some similar filtering to response.data.registrants:

const items = response.data.registrants
const desiredStatus = "approved"; // or "pending" or "denied"
const filtered = items.filter(item => item.status === desiredStatus);

Hope this helps.

EDIT: Made my example code a little bit more perfomant haha

1 Like

Hi Alex,

Thanks a lot for your reply. But is there a way to get a filtered response from the api itself, particularly the webinar one. Like get only webinars where registration is till open and start time greater than today for example.

Hi @Ramprabhu
The List webinar registrant endpoint, offers a query param for status. But the List webinar participants does not have a query param for filtering. So I’d agree with @alexm and you would have to manage the filtering yourself

I do not believe you can make a request for webinars for a specific date or date range; as for the registration status, I don’t believe even the more granular webinar GET request returns that level of detail, either.

1 Like

Have to love the concise code, adding this to my library.

john

1 Like