cronofy / cronofy-node

Node wrapper for the Cronofy API
https://docs.cronofy.com/developers
MIT License
49 stars 23 forks source link

Add an option to readEvents to filter by calendar_id #59

Closed nabilfreeman closed 5 years ago

nabilfreeman commented 5 years ago

Hey there, I noticed that when managing multiple large calendars for one user it takes a while to paginate and fetch all events using client.readEvents.

It's already useful to be able to specify date range but it would also be great if we could specify the calendar_id to do the filtering server-side.

There already seems to be a way to do it with the REST API:

https://www.cronofy.com/developers/api/#read-events-calendar_ids[]

nabilfreeman commented 5 years ago

Update: I figured it out embarrassingly fast after posting this by looking at the plugin source code.

You can actually add any of the API params into the options object and the plugin will serialise them and automatically create the request.

var options = {
    //from: '',
    //to: '',
    //next_page: '',
    calendar_ids: ['cal_xxxxxxx']
}

//this will pull all the events just for a specific calendar id (or more if you add them to the array above).
const result = await client.readEvents(options)

did the trick!

stephenbinns commented 5 years ago

Great glad you've found the answer, ill have a look at updating the documentation