Unable to create user account using web api

Hello everyone,

I’ve encountered a problem while trying to make a PUT request to the https://api.nuki.io/account/user endpoint using Python’s requests library. Here’s the code I’ve been using:

import requests

url = 'https://api.nuki.io/account/user'
header_info = {
    "authorization": "Bearer 0123456",
    "Accept": "application/json",
    "Content-Type": "application/json"
}
payload = {
    "email": "test@gmail.com",
    "name": "user",
    "language": "en"
}
result = requests.put(url=url, headers=header_info, data=payload).json()
print(result)

Upon execution, I receive the following error:

{'code': 422,
 'description': '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',
 'homeRef': '/',
 'reasonPhrase': 'Unprocessable Entity',
 'uri': 'http://www.webdav.org/specs/rfc2518.html#STATUS_422'}

Interestingly, I managed to obtain a successful response using both Swagger and a CURL command. I’m trying to figure out what’s going wrong with my Python request.

Any help or advice would be greatly appreciated!

1 Like

I have the same problem how you solved it

Replace the “data” field with “json” field in the requests.put function