I think you're missing api in the path. In general I recommend comparing your API requests with what the official web app sends.
if I api I got this error :
Error updating device accumulators: 400 Client Error: Bad Request for url: https://traccar.ipcs.synology.me/api/devices/4/accumulators
If I try to reset the totaldistance from the web UI, the url is :
https://traccar.ipcs.synology.me/settings/accumulators/4
what is correct ?
I'm talking about the API web uses, not the web page URL.
ok, but if I add api in the url I got error 400
I am new with traccar, how to see the API web use ?
Typically you would use your browser developer tools. It's not Traccar specific.
ok, but with python, I have no browser developer tools ?
must the api be added in the url ?
https://traccar.ipcs.synology.me/api/devices/4/accumulators
but with api added I got an error 400
and without api I got an error 405
thanks for your help
ok, it works now... the json was not good
yv67,
It would be helpful if you detailed WHAT was wrong with your JSON. These pages aren't just to help YOU personally, but also, perhaps for hundreds of others who may encounter the same problem.
voici le script python qui fonctionne :
il faut mettre la liste_devices des id des trackers à jour, ici je n'en ai qu'un avec ID = 1
et aussi user, mot de passe et adresse du traccar
import json
import requests
Traccar_user = 'XXXXXXXXXXXXX'
Traccar_password = 'XXXXX'
headers = {'Content-type': 'application/json'}
liste_devices = [1]
def get_device_data(device_id):
url = f"https://traccar.ipcs.synology.me/api/devices/{device_id}"
response = requests.get(url, auth=(Traccar_user, Traccar_password), headers=headers)
return response.json()
def raz_totaldistance(device_id):
data = {'deviceId': device_id, 'totalDistance': 0, 'hours': 0}
url = f"https://traccar.XXXXXXXXXX/api/devices/{device_id}/accumulators"
response = requests.put(url, auth=(Traccar_user, Traccar_password), headers=headers, json=data)
return response
if __name__ == "__main__":
for device_id in liste_devices:
# device_data = get_device_data(device_id)
# nom = device_data["name"]
# print(f"Device Data: {device_data}")
# print(nom)
response = raz_totaldistance(device_id)
# print(response)
exit()
I am trying to update the toaldistance and hours with a python script
but I got an error 405
here is my python script :
I am stuck, thanks for any help