Hi,
I want to add a user over php script like as follow.
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new GuzzleHttp\Client();
$res = $client->request(
'PUT',
'https://api.nuki.io/account/user',
[
'headers' => [
'Accept' => 'application/json',
'Authorization: Bearer' => 'My API token',
'd' => '{"email": "mail@company.com","name": "Max Mustermann"}'
],
]
);
?>
But I get this Error
Client error: PUT https://api.nuki.io/account/user resulted in a 400 Bad Request response: {“code”:400,“description”:“The request could not be understood by the server due to malformed syntax”
Can you help me please ?
Not a PHP dev, so just a quick guess, but it seems to me like you have the body (user email/name) in the headers instead of in the request body, where they should be.
Just another wild guess: make sure you’re sending the type parameter as an integer, not as a string. Likely like this:
'body' => json_encode([
'email' => 'mail@company.com',
'name' => 'Max Mustermann',
'language' => 'de',
'type' => 0 // Note that there are no quotes here
])
@joshuajung Thank you for your notice,
but even if I use with quotes ‘type’ => ‘0’ or not ‘type’ => 0
I get the same error message
Client error: PUT https://api.nuki.io/account/user resulted in a 400 Bad Request response: {“detailMessage”:“The supplied value ‘0’ for parameter ‘type’ is not valid”,“stackTrace”:[],“suppressedExceptions”:[]}
This option is only needed for special Nuki Web account types and so is not usable when the API token used to create the account user is not of this type.
This is something which needs to be made clear in the documentation and I will try to get an update for that as soon as possible.