NUKI not creating entry codes even on successful response

Hello,
we are using NUKI api in our system. Exactly PUT /smartlock/{id}/auth to create NUKI codes with ability to put them onto smartlock and open the door.

Exactly we are sendin
PUT https://api.nuki.io/smartlock/{$smartlockId}/auth

Example of failed body:
{“accountUserId”:1050067519,“type”:13,“code”:969281,“name”:“2411221730-2363”,“allowedFromDate”:“2024-11-22T16:30:00.000000Z”,“allowedUntilDate”:“2024-11-22T18:00:00.000000Z”,“allowedWeekDays”:127,“allowedFromTime”:0,“allowedUntilTime”:0,“remoteAllowed”:true,“smartActionsEnabled”:true}

We got almost always response with no Error and status code 200/204. But unfortunately we some times experiences weird behavirour on NUKI smartlock that some codes are not present! We not receiving any of the error and if we receive error we have repeating session to try create code as many times as possible. But unfortunately we almost always get good HTTP codes.

Can you please help me, what is going on? What HTTP status code means everything is ok?

Implementation of creation new nuki code is following

private static function generateNewCode()
{
    while (true) {
        $code = fake()->numberBetween(111111, 999999);

        $str = (string)$code;
        if (str_contains($str, '0')) continue;
        if (str_starts_with($str, '12')) continue;
        if (NukiCode::where('code', $code)->exists()) continue;

        return $code;
    }
}

Are there some further limitation of creating nuki codes?

Sometimes we get also 502 error, or Operation timed out after 30001 miliseconds. Is this errors common? We usually repeat after this so we have safe operations. But most of the times we got OK result and no NUKI code in smartlock.

Thank you for all your support

Hello,

I believe you are not using webhooks.
In this case,

The Nuki Web API is asynchronous. When you send a command, you will get an immediate OK response (i.e. 200, or in this case 204) which means that the request has succeeded, but that doesn’t guarantee that the client has executed the request successfully. Once the server has received the API call, it will try to reach the Smart Lock and create the code (all the codes are stored on the Smart Lock itself). This usually takes some seconds, and the device should be online.

Thus, call the GET /smartlock/auth endpoint within a few minutes to validate if the auth was created successfully.

The auths may not be created successfully if the devices were not online during this time.

However, you can avoid this situation if you use webhooks as the best practice recommended is to use webhooks.

Regarding 502 errors, was it only in the recent past last week or has it always been the case? Our system is going through a planned infrastructure update and thus you may have experienced some unplanned downtime in the past week, which we are working on resolving at the earliest.

Hi Poonam Chavan,

I don’t understand your reply completely. Are you saying that when making a PUT request to https://api.nuki.io/smartlock/{$smartlockId}/auth there’s actually no way to know if the request was successful? Because when it returns status 204 it doesn’t necessarily mean it was successful? Isn’t this very inconvenient?