Traccar API

Developer6 years ago

After login success, to get objects like geofence always send _dc, how to get this token?

Developer6 years ago

after login, i try to get devices:

function getDevices() {
                $.ajax({
                    url: 'http://localhost:8089/api/devices/',
                    dataType: 'json',
                    //data: {page: 1, start: 0, limit: 25},
                    type: 'post',
                    headers: {
                        'Access-Control-Allow-Origin': '*'
                    },
                    //headers: {'X-Requested-With': 'XMLHttpRequest'},
                    //data: {_dc:session,all: true, userId: user_id},
                    success: function (result) {
                        console.log(result);
                    }
                })
            }

but i get response like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
    <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 2.25.1 2017-01-19 16:23:50"/>
    <grammars/>
    <resources base="http://localhost:8089/api/">
        <resource path="devices/">
            <method id="get" name="GET">
                <request>
                    <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="all" style="query" type="xs:boolean"/>
                    <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="userId" style="query" type="xs:long"/>
                    <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="uniqueId" style="query" type="xs:string"/>
                    <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                </request>
                <response>
                    <representation mediaType="application/json"/>
                </response>
            </method>
            <method id="add" name="POST">
                <request>
                    <representation mediaType="application/json"/>
                </request>
                <response>
                    <representation mediaType="application/json"/>
                </response>
            </method>
            <resource path="{id}/distance">
                <method id="updateTotalDistance" name="PUT">
                    <request>
                        <representation mediaType="application/json"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
            </resource>
            <resource path="{id}">
                <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="template" type="xs:long"/>
                <method id="remove" name="DELETE">
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="update" name="PUT">
                    <request>
                        <representation mediaType="application/json"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
            </resource>
        </resource>
    </resources>
</application>

what wrong

Anton Tananaev6 years ago

You don't need _dc parameter.

I'm not sure how you managed to get this response. What if you just open URL in browser?

Anton Tananaev6 years ago

Wait, your request is obviously incorrect. You are trying to do POST without any data.

Developer6 years ago

thank you this problem solve...