1
votes

I'm using Microsoft's sample Django app and trying to read calendar events from now back to 1 year ago. The API request is done using Python Request functions:

response = requests.get(url, headers = headers, params = parameters)

Header is standard API request related:

headers = { 'User-Agent' : 'python_events/1.0',
            'Authorization' : 'Bearer {0}'.format(token),
            'Accept' : 'application/json',
            'X-AnchorMailbox' : user_email }

And, for parameters I'm passing:

  query_parameters = {'$top': '2500',
                      '$select': 'Id,Subject,Start,End',
                      '$orderby': 'Start/DateTime ASC'}

Now, I tried to define start and end dates as:

  now = datetime.utcnow()
  one_year = now - timedelta(days=365)
  now = now.isoformat()
  one_year = one_year.isoformat()

Then, tried to insert startDateTime and endDateTime parameters in the same query_parameters dict:

  query_parameters = {'$top': '2500',
                      '$select': 'Id,Subject,Start,End',
                      '$orderby': 'Start/DateTime ASC',
                      'startDateTime' : one_year,
                      'endDateTime': now
                     }

I'm still getting event dumps from before a year ago. What am I doing wrong here? Is query_parameters the right place to insert start and end date and times?

1
What is the value of url?Jason Johnston
Hi Jason, the url value is: outlook.office.com/api/v2.0/Me/EventsBhushan Shinkre

1 Answers

0
votes

In order to use the startDateTime and endDateTime parameters to limit the date range, you need to do a GET on the /calendarview endpoint, not /events. The /events endpoint doesn't support those parameters.

Change your url to https://outlook.office.com/api/v2.0/Me/calendarview and see if you get better results.