Thank you for your reply.
In the example there is nothing mentioned about encoding. it looks to me like the data is just plain JSON. But I get the error 500 when I send it like that.
looks like this:
{
"folderId":"3179303d-4b09-4c37-89fd-aed800f8476c",
"type":1,
"notes":"None",
"login":{
"uris":[
{
"uri":"None"
}
],
"username":"Administrator",
"password":"MyPassw0rd!",
"totp":"None"
},
"name":"Administrator"
}
Then I tested it with the following headers and without:
headers = {
'Content-Type': 'application/json',
'accept': 'application/json'
}
When I send it with headers, I get an error 400
SyntaxError: invalid JSON, only supports object and array
When I send it without headers, I get an error 500
Error: Unknown cipher type.
Edit: I got it to work!
I will leave this comment up for anyone who wants to do this in the future or gets a similar error.
I use Python with the requests library to send the HTTP requests.
For it to work the data dict needs to be converted to a string using the JSON library and then the headers need to be added to the request, before that I just added the data as a dict and let the requests library do the conversion but that does not work.
Example:
import json
import requests
BASE_URL = 'http://127.0.0.1:8087'
def create_entry(name: str, username: str = "", password: str = "", uri_list: list = None, notes: str = "",
folder_name: str = "Keepass-Default", **kwargs):
target_url = f'{BASE_URL}/object/item'
login_data = {
"uris": uri_list,
"username": username,
"password": password,
"totp": None
}
folder_id = get_folderid(folder_name)
data = {
"folderId": folder_id,
"type": 1,
"notes": notes,
"login": login_data,
"name": name,
}
json_data = json.dumps(data)
headers = {
'Content-Type': 'application/json',
'accept': 'application/json'
}
s = requests.Session()
r = s.post(target_url, timeout=20, data=json_data, headers=headers)
return r.json()['data']