title: How to use traccar api to get devices
body: <p>i have done research on google and many other page, that i can extract the data via traccar api <a href="https://www.traccar.org/traccar-api/" rel="nofollow">here</a> so i do next research how to use it, and finally find this answer <a href="https://www.traccar.org/forums/topic/need-help-with-api-to-create-a-ios-app/#post-6204" rel="nofollow">here</a> by mvalverde. At that post, he write some code, like this:</p>
  
  <pre><code>// find All devices  - GET request
  var result = HTTP.call(
      "GET",
      'http://your_domain:8082/api/devices/',
      {
          auth: 'email@xyz.com:password' ,
          params: {
          }
      }
  );
  
  // add device
  var name = 'name your device';
  var uniqueId = '122323223232'; // usually this is the device imei
  var result = HTTP.post(
      'http://your_domain:8082/api/devices/',
      {
          auth: 'email@xyz.com:password' ,
          data:{
              groupId:null,
              id: null,
              lastUpdate:null,
              status:'',
              name:name,
              uniqueId:uniqueId
          }
      }
  );
  </code></pre>
  
  <p>he said it is javascript, so i try implement in javascript way:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;try traccar api&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script type="text/javascript"&gt;
        var result = HTTP.call(
          "GET",
          'http://103.23.20.176:8082/api/devices/',
          {
            auth: 'email:password' ,
            params: {
            }
          }
        );
        console.log(result);
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>but i get error in console. i suspect that it is not a pure javascript, if it so can u guide me to write the implementation using javascript. so anyone can you help me solve this problem. </p>
  
  <p>ps : i am still rookie in js field </p>
  
  <p>== UPDATE == <br>
  thanks to anton tananaev, i solve this problem, like this:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;try traccar api&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script src="js/jquery-2.2.2.min.js" charset="utf-8"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        $.ajax({
          type: 'get',
          url: 'http://103.23.20.176:8082/api/devices/',
          headers: {
              "Authorization": "Basic " + btoa("admin:admin")
          },
          success: function (response) {
              console.log(response);
          }
        });
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and 1 question again, how to post data? i try like this:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;try traccar api&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script src="js/jquery-2.2.2.min.js" charset="utf-8"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        var name = "Bus 2";
        var uid = "1212321233";
        $.ajax({
          type: 'post',
          url: 'http://103.23.20.176:8082/api/devices/',
          headers: {
              "Authorization": "Basic " + btoa("email:pass")
          },
          data:{
            id:null,
            name:name,
            uniqueId:uid,
            groupId:null,
            status:'',
            lastUpdate:null
          },
          success: function (response) {
              console.log(response);
          }
        });
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>but i get status code 415 unsupported media type. what i miss in my code?</p>
  
  <p>== CLOSED == <br>
  final code for the next question is here,</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;try traccar api&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script src="js/jquery-2.2.2.min.js" charset="utf-8"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
        var name = "Bus 3";
        var uid = "1243232133";
        $.ajax({
          type: 'post',
          url: 'http://103.23.20.176:8082/api/devices/',
          headers: {
              "Authorization": "Basic " + btoa("email:pass")
          },
          contentType:"application/json",
          data:JSON.stringify({
            name:name,
            uniqueId:uid
          }),
          success: function (response) {
              console.log(response);
          }
        });
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>thank you, i solved my problem :)</p>