Need help with API to create an IOS APP

elekira018 years ago

Hi everyone
I am trying to make an IOS APP using swift with the public API that traccar have i think is version 3.3.
I know they are a documentation file on the web that need to open with swagger editor but i need a example how can i make any request like login,getting device info etc from my server using the api.
Example if i want to know a device info how can i do that?
Please give me a detail example i dint understand the api documentation
Thank you for all.

mvalverde8 years ago

Hello, I hope these examples can serve as a starting point. excuse my English, I'm using google translator.

Examples are in javascript. but I guess for ios, must exist any command that request GET or POST requests.

// 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
        }
    }
);

with these examples I think you can already make your ios applications. requests for more GET PUT POST DELETE, check the swagger file. you only need to know what type it is (GET, POST, PUT, DELETE) and parameters.

luck

elekira018 years ago

Thank you bro!
I have another question...if i need to retrieve information like speed,latitud longitude how can i do that?
Another question:
In the api documentation the userId parameter refers to what?
Thank you all

Anton Tananaev8 years ago

If you want an example of how to use API from Swift, you can take a look at Traccar Manager for iOS source code:

https://github.com/tananaev/traccar-manager-ios

mvalverde8 years ago

Hello again.

when you create traccar users (admin or normal), this in the database generates a unique id. this unique id refers when documentation ask the userId

cuando uses REST en traccar, te daras cuenta que necesitas identificarte.

 auth: 'email@xyz.com:password' 

if that identification of an administrator. then in REST applications, you can put any other user userId and you will return your data.

but if it is not an administrator, then only you would return your data from your devices for that user.

if you are an administrator and want to see all devices including other users can use the parameter all: true

params: {all:true}

or users requesting user terminals by putting your userId
params: {userId: 1}

sorry if you do not understand me. I'm using google translator from Spanish to English

mvalverde8 years ago

answering your questions

to request the latest positions with all the data.
you need to request a GET request to

'http://your_domain:8082/api/positions'

luck

elekira018 years ago

Thank you all for yours answersssssssssssss!!!!
Thank you i am going to try everything !

elekira018 years ago

Thank you!!!!!!!!!!!!!!!!!! :)

mtrntx8 years ago

This example in javascrip is angular??

shernandez8 years ago

Hola mvalverde.
Veo que ya has trabajado con el API de Traccar, yo hasta ahora estoy comenzando y tengo varias dudas. Me gustaría saber si tienes un ejemplo para enviar una orden a cualquier dispositivo como lo indica Anton en otro foro.

"There is also an option in API to send raw text commands to any device."

Muchas Gracias

darreno8 years ago

Hi all,

You can generate all types of code: php client, android client, swift client, etc by using the swagger-editor at http://editor.swagger.io/

mvalverde8 years ago

mtrntx => example is in Meteor js

shernandez =>
No tengo muchos ejemplos para la api todavia, pero pongo el que uso para apagar un vehículo.


var result = HTTP.post(
    'http://domain:8082/api/commands',
    {
        auth: 'email@xyz.com:password',
        data:{
            deviceId:idDevice,
            type: 'engineStop'
        }
    }
);

Para prender solo es cambiar 'engineStop' por 'engineResume'. Y no olvidarse que idDevice es el id en la base de datos del vehículo en cuestión y asociado al usuario traccar email@xyz.com.

Y todos los comandos los puedes desarrollar siguiendo http://editor.swagger.io/ para cualquier lenguaje.

euoraf48 years ago

Friend, you got a solution? I have the same problem.

If you can share.

elekira018 years ago

You can download the example project that is in this post and have an example !!!!

euoraf48 years ago

I downloaded the project but it returns me an error , I can not compile.

Returns this message, even the file being it.

bridging header '/Users/rafamelo/Downloads/traccar-manager-ios-master/TraccarManager/BridgingHeader.h' does not exist

even the file being it