Web API Example: Manage PIN-Codes for your Nuki Keypad

Hi!

Just tested it with

{"name": "Test", "type": 13, "code": 999999, "allowedFromDate": "2020-03-19T16:00:00.000Z", "allowedUntilDate": "2020-03-20T16:00:00.000Z","allowedWeekDays": 0}

and had no issue creating.

The problem seems to arise when you miss to add the "allowedWeekDays": 0

Thanks, that helped!
As a question, could the api may improved with a debug parameter where helpful error messages come back? That would help debugging such problems without the Forum.

Thanks for your time and assistance!

Hi. I succeed to get the smartlock Id without problems, but when I try to create new pinpad key I recieve the following error code: 400 BAD REQUEST.
My code in PHP:
<?php
$url = ‘https://api.nuki.io/smartlock/593895460/auth’;
$ch = curl_init($url);
$data = array(
‘name’ => ‘TEST’,
‘type’ => 13,
‘code’ => 999999,
‘allowedFromDate’ => ‘2020-12-01T16:00:00.000Z’,
‘allowedUntilDate’ => ‘2020-12-09T16:00:00.000Z’,
‘allowedWeekDays’ => 0
);
$jsonData = json_encode($data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Accept: application/json’,‘Content-Type: application/json’,‘Authorization: Bearer dcbe2e69424747028b92b9bfdef444cefc26127cf7dd3c35153006ebd35694ef0254d21cefc65665’));
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,“PUT”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
?>
Can somebody tell me where is the probelm? Thank you.

Can you also provide the Body of the response? It should contain more details on the reason the request failed.

Hi Stephan,

First of all I wish to thank you for these solutions and to your help.
I found the problem. There is.

The curlopt_put is working with files, and server aspect for file. I used just CURLOPT_CUSTOMREQUEST and everything is working fine.

The complete solution to create access codes in php:

Best regards,
Zoli B.

1 Like

Hello Stephan,
The expired (after “allowedUntilTime”) entry codes are automatically deleted, or we have to find them and delete one by one?
Thank you,
Zoli B.

No, currently there is no option to create authorizations which are automatically deleted after end-date has passed. You have to have your own routine doing that.

Thank you. A cron job will solve the problem.

Hello, thanks for the API. It works well, except for the list of users. I request the https://api.nuki.io/smartlock/SMARTLOCK_ID/auth URL to retrieve the list of “users”, but it looks like the list is cached and doesn’t reflect the current list of PINs/users in the application. The response headers contain the Date 2 hours older than the current date and the Expires header is set to Jan 01 1970 which means never, right? Am I missing something here? Thanks a lot.

Hi @kordys!

The list is cached server-side, but changes should be updated from the device. In doubt you can try a

POST /service/{serviceId}/sync

(Note: This will sync complete data directly from the device, meaning it should not be used too often to avoid battery drain.)

to check if data is correctly updated then.

Thanks Stephan for the reply. Apparently, the cache is not always flushed correctly? I will give it a try. Maybe it was just some sort of glitch on my side.