LDJ LDJ - 1 month ago 21
Node.js Question

Filtering Outlook Calendar API results by date

I'm using Node (specifically the node-outlook npm module) to pull through my Outlook.com calendar and the base request is working. I'm getting back results from the API, but I'm having trouble with the oData request parameters to only reutrn results for today. Here's what I've got:

var queryParams = {
'$select': 'Subject,Start,End',
'$orderby': 'Start/DateTime desc',
//'$top': 10,
'startDateTime': startDateString,
'endDateTime': endDateString
//'$filter': "Start/DateTime ge " + startDateString + " and Start/DateTime le " + endDateString

};

outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');
outlook.base.setAnchorMailbox(<my email address>);
outlook.base.setPreferredTimeZone('Europe/London');

outlook.calendar.getEvents({token:token, odataParams: queryParams},function(error, result){
//Do some stuff with the event data here
}


However, if I use the parameters are shown above (where startDateString is
2016-10-28T00:00:00
and endDateString is
2016-10-28T23:59:59
) I'm still getting back events both in the past and in the future.

This isn't what I want - what I was hoping to do was just pull through the current days events (hence the attempt at useing the oData
$filter
, but the API doesn't seem to like that and it moans about incompatible binary operators).

Can anyone advise what I need to amend in the params to just get back events scheduled for today?

Thanks

EDIT: Here's an example of what I'm getting returned:enter image description here

LDJ LDJ
Answer

Figured it out (or at least this SO question did it for me)

It turns out the times need to be enclosed in quotes!

var queryParams = {
                '$orderby': 'Start/DateTime desc',
                '$filter': "Start/DateTime ge '" + startDateString + "' and Start/DateTime le '" + endDateString + "'"

            };

And now its working.

Grrr!