LDJ LDJ - 4 months ago 55
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.setAnchorMailbox(<my email address>);

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
and endDateString is
) 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
, 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?


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


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.