Curl to add odometer record - invalid object
psyciknz opened this issue · 6 comments
No Idea what I'm missing here, any guidance?
curl -v -H "Content-Type: application/json" \
-u hass:Mypass \
--data '{"date": "07/08/2024","odometer": 130034,"notes": "From Traccar"}' \
"https://lubelog/api/vehicle/odometerrecords/add?vehicleId=1"
gets the following error
{"success":false,"message":"Input object invalid, Date and Odometer cannot be empty."}
Is Date and Odometer supposed to be initial caps? Or lower.
I can't speak to the why, but I believe it's around the content-type header. The following works for me:
curl -v "{{url}}/api/vehicle/odometerrecords/add?vehicleId=1" \
-H "Content-Type: multipart/form-data" \
-F "date=1/1/1970" \
-F "initialOdometer=0" \
-F "odometer=111" \
-F "notes=CURL test"
This fails however, with the same 400 Bad Request that you saw.
curl -v -H "Content-Type: application/json" \
--data '{"date": "1/1/1970", "initialOdometer": 0, "odometer": 111, "notes": "CURL test2"}' \
"http://172.16.1.50:8088/api/vehicle/odometerrecords/add?vehicleId=1"
Yeah with python I had issues as well.
If I post as requests(url, json=payload). It had the same problem.
Only when I switched to requests(url,data=payload). Did it work.
I was going to post from home assistant. But that seems to send it as b'{ 'odometer': 1234 }'. Which also fails.
But finally got it working using the python, triggered by mqtt from home assistant.
So I have an odometer record being posted each day from the latest figures that traccar stores.
This question was asked every now and then(example Reddit post), so I added the solution to the troubleshooting guide:
I don't believe those updates to the trouble shooting cover the issue. As neither of us had issues connecting.
Our issues and investigation related to the response triggered by the out being empty, and most likely encoded wrong.
Ahh sorry, was on phone and didn;t see sections could be expanded