Web API Example: Renting a classroom / rehearsel space

You can use our API to directly push bookings from a calendar per day.

(Note: It is not possible to enable several different time windows for one day at once atm!)

Authenticate

See Authentification. Use the access token as e.g. ACCESS_TOKEN.

Preliminary Remarks

Even if you just want to have keys valid for some hours a day the allowedFromDate has to be set to restrict an authentication to specific times and dates!

allowedUntilDate should also be set to avoid unwanted valid keys in the future, as they will not be removed - just overwritten - in the specified process.

date format = YYYY-MM-DDTHH:MM:SSZ

(You can also use YYYY-MM-DDTHH:MMZ)

allowedUntilDate can be left empty to set no end date.

Days are set via bitmask:

Day Bitmask Value
Monday 01000000 64
Tuesday 00100000 32
Wednesday 00010000 16
Thursday 00001000 8
Friday 00000100 4
Saturday 00000010 2
Sunday 00000001 1

e.g. Monday + Wednesday + Friday = 64 + 16 + 4 = 84
Not setting a value also allows all weekdays.

Time restrictions are set as “minutes from midnight”, e.g.:

Time Minutes
08:00 8 am 480
11:00 11 am 660
17:00 5 pm 1020
19:00 7 pm 1140

Example call:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 
'Authorization: Bearer ACCESS_TOKEN' -d '{ \
"allowedFromDate": "YYYY-MM-DDTHH:MMZ", \
"allowedUntilDate": "YYYY-MM-DDTHH:MMZ", \
"allowedWeekDays": WEEKDAYS_BITMAP, \
"allowedFromTime": MINUTES_FROM, \
"allowedUntilTime": MINUTES_TO\
}' 'https://api.nuki.io/smartlock/SMARTLOCK_ID/auth/KEY_ID'

Case 1: Fixed time

A band books a rehearsal room every monday from 7pm to 10pm for the whole year 2019. We will set their access key once. And we give them 5 minutes grace period to enter and leave the room.

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 
'Authorization: Bearer ACCESS_TOKEN' -d '{ \
"allowedFromDate": "2019-01-01T00:00Z", \
"allowedUntilDate": "2019-12-31T23:59Z";, \
"allowedWeekDays": 64, \
"allowedFromTime": 1135, \
"allowedUntilTime": 1325 \
}' 'https://api.nuki.io/smartlock/SMARTLOCK_ID/auth/KEY_ID'

Case 2: Flexible schedule

Our rehearsal room can be booked from day to day by calendar. We don’t want to set up new keys for returning users as this would not be feasable. The idea is to instead push keys for the next day every night.

You can achieve this via 2 different ways:

Example 1: Monday, 7th Jan 2019, 7pm - 10pm with grace period:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header ' Authorization: Bearer ACCESS_TOKEN' -d '{ \
"allowedFromDate": "2019-01-07T00:00Z", \
"allowedUntilDate": "2019-01-07T23:59Z", \
"allowedWeekDays": 64, \
"allowedFromTime": 1135, \
"allowedUntilTime": 1325 \
}' 'https://api.nuki.io/smartlock/SMARTLOCK_ID/auth/KEY_ID'

Example 2: Thursday, 8th Jan 2019, 10am - 11am with grace period:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer ACCESS_TOKEN' -d '{ \
"allowedFromDate": "2019-01-08T09:55Z", \
"allowedUntilDate": "2019-01-08T11:05Z" \
}' 'https://api.nuki.io/smartlock/SMARTLOCK_ID/auth/KEY_ID'

With example 1 being more flexible overall.

For even more complex usecases we suggest you contact us for a full Short Rental Integration.

This topic will contain a table of contents

Fixed a small error in a code example.

In my case, dates don’t work, I get error: The server understands the content type of the request entity and the syntax of the request entity is correct but was unable to process the contained instructions. I use culs form Linux.

  • Next does not work: {‘allowedFromDate’: ‘2019-08-24T15:44:05.000Z’}
  • Whereas this does work or at least I get no error: ‘{‘allowedFromDate’: 156663478}’

Finally it worked out by filling almost all fields.

Sorry for missing your first question. You exactly could you solve your issue? What could be changed in the example that misslead you in the first place?

That is very good question, @Stephan, as I am facing the same issue it would be great to get more infos here…

Answered in the post here: BUG in smartlock/auth allowedFromDate? - #9 by poonam.chavan