surya singh surya singh - 16 days ago 5
reST (reStructuredText) Question

Outlook Rest Api -- Get a calendar view (REST) in particular timezone

I'm trying to retrieve a calendar view in particular time zone. According to Docs we need to use the Prefer: outlook.timezone header to specify the time zone. But after setting the prefer header the api is returning 400 error status.

var queryParams = {
'startDateTime' : params.timeMin,
'endDateTime' : params.timeMax,
'$select': 'Start,End'
}
// header
var headers = {
'Prefer' : 'Asia/Kolkata'
}
request.get({url:'https://outlook.office.com/api/v2.0/me/calendarview',
qs:queryParams,
json:true,
'auth': { 'bearer': token},
headers: headers
}, function(error, response, body) {

});

Answer

You need to change

var headers = {
    'Prefer' : 'Asia/Kolkata'
};

to

var headers = {
    'Prefer' : 'outlook.timezone="Asia/Kolkata"'
};

In case of header 'Prefer' : 'Asia/Kolkata' server responds with invalid Prefer header error.

The valid format for Prefer header is:

Prefer: outlook.timezone="<time zone>"

References

List of tz database time zones