I am trying to use the google-api-nodejs-client in Node.js. I have a problem with the format of the timeMin parameter in the freebusy query. According to the docs, the value should be timedate in ISO format. I tried that but I got an error. In the event.list method the ISO format string works fine.
Query freebusy code:
function freeBusyStatus (auth, calendarId) {
const startDate = new Date('20 February 2018 12:00').toISOString()
const endDate = new Date('20 February 2018 13:00').toISOString()
const check = {
auth: auth,
// timeMin: '2018-02-20T12:00:00+03:00', //not working with same format too
timeMin: new Date('20 February 2018 12:00'),
timeMax: endDate,
items: [{id: calendarId}]
}
calendar.freebusy.query (check, function (err, response) {
if (err) {
console.log ('error: ' + err)
} else {
..some code..
}
})
}
And code events.list with dates in the ISO format. This code works:
function listEvents(auth, calendarId) {
const eventList = {
auth: auth,
calendarId: calendarId,
timeMin: new Date('20 February 2018 12:00').toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime'
}
calendar.events.list(eventList, function(err, response) {
if(err) {
console.log(err)
}
const events = response.data.items
if (events.length != 0) {
..some code..
}
})
}
I think that the problem is with the date format. When I try to send a request with dates like 2018-02-20 (without time), the response has the same error Error: Missing timeMin parameter.
What am I doing wrong? Authorization is done with JWT.
Done! My mistake was with structure of request
function freeBusyStatus (auth, calendarId) {
const check = {
auth: auth,
resource: {
timeMin: startDate,
timeMax: endDate,
items: [{id: calendarId}]
}
}
const startDate = new Date('20 February 2018 12:00').toISOString()
const endDate = new Date('20 February 2018 13:00').toISOString()
calendar.freebusy.query (check, function (err, response) {
if (err) {
console.log ('error: ' + err)
} else {
..some code..
}
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With