API

Steenkamp5 years ago

Hi Anton,
I'm frustrated. What am I doing wrong here. All I want to do is change the device's phone via API.
To get it, works 100%, but not update.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>try traccar api</title>
  </head>
  <body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript">

    var data;

    function callback(devicedata) {

        


        
        $.ajax({
                type: 'post',
                url: 'http://xxx.xxx.xxx.xxx:8082/api/devices/',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify({
                       id: 978,
                       phone: 'xxxxxx'
                }),
            beforeSend: function (xhr) {
                        xhr.setRequestHeader ("Authorization", "Basic " + btoa("admin:admin"));
                },
                success: function (response) {
                        console.table(response);
                },
                error: function (response) {
                        console.log(response);
                }
             });

          
        
    }

    $.ajax({
            type: 'get',
        global: false,
        contentType:"application/json",
        	url: 'http://197.221.52.122:8082/api/devices/',
        data: {uniqueId:356307044107505},
            headers: {
                "Authorization": "Basic " + btoa("admin:admin")
            },
            success: function (response) {
                 callback(response);

            }
    });


    
     
    
    

    </script>
  </body>
</html>
Anton Tananaev5 years ago

You have to send full device model, not just 2 fields.

Steenkamp5 years ago

Than you.