JSON API

demian10 years ago

Hello,
I was wondering if currently traccar exposes a JSON API to retrieve information about device's positions. I haven't found any docs about it, but looking at the source code there seems to be some JSON conversions but I couldn't figured it out if it can be used from outside.

It would be possible to directly read from the database, but having an API would be nicer, since it would be easier to put different applications on different machines.

If it is not implemented, is it something that would be interesting for the project? If that is so, I could consider implementing.

Thanks in advance!

Anton Tananaev10 years ago

Current (latest release) version doesn't support JSON API, but I'm working on new web interface and JSON API for it which is what you see in the code on GitHub. I haven't finished it, so there is no documentation at this point.

demian10 years ago

If you can tell me the guidelines for developing the API I can use some hours to implement it. At least I can give you a hand with the JSON API part and we can finish it soon. Would that be ok?

demian10 years ago

As a little update, I managed to run the server and debug it in the IDE, and also package it and run it independently.

With the h2 database everything seemed to run, but on MySQL there where some problems with the size of the unique indexes (which has a limit of 767 bytes ~ something around a varchar(200)), and some functions that I think are h2 specific (like HASH, STRINGTOUTF8).

I am eager to help you with this feature, so I would really like if we can coordinate the efforts.

Thanks in advance!

Anton Tananaev10 years ago

MySQL config is not ready yet, but I will work on it soon.

demian10 years ago

Can I help you with that? I am working to integrate traccar server with our application so we can put it in production to handle some ~100 cars. So I can use some of my work time to help you finish this feature sooner :)

Anton Tananaev10 years ago

I plan to move all SQL queries to the config file soon and then you can try to adopt them to MySQL if you want.

Alternatively you can try to do it now by changing DataManager class:
https://github.com/tananaev/traccar/blob/master/src/org/traccar/database/DataManager.java

demian10 years ago

Hi, I had some time today and I implemented both things. I moved all the sql queries to the config file, and made some changes to make it MySQL compatible.

I left a pull request (https://github.com/tananaev/traccar/pull/1240) for you to see it. If there is anything to correct, let me know please!

Anton Tananaev10 years ago

Does it work with both H2 and MySQL database engines?

demian10 years ago

Yes :)

Anton Tananaev10 years ago

I have made some comments on the pull request.

Good job by the way. This will save me a lot of time.

demian10 years ago

I have added the modifications you suggested and left another comment there. Why the way, against which Java version should we be working? I am currently sticking to Java 6, but I am also missing the new parts which might be handy

Thanks!

Anton Tananaev10 years ago

For now Java 6. I really want to switch to Java 7, but it seems like there are too many servers still running Java 6.

I want to update to new version of Jetty, but it requires Java 7.

gabrielcz10 years ago

Hi all... very nice forum idea, different from hit hub...
We (hansen and me) more him that I, are working on a integration of our agro management software on symphony and traccar.

Question: If we want to use api jason to create devices, and other stuff, is better to wait, or we have something to start with?
Theres anyway to help with JASON/API?

Sorry for my english, we speak spanish.
Regards,

Anton Tananaev10 years ago

Most of the API is already available on GitHub master branch, so you can use it if you want. Unfortunately there is no documentation yet, so you need to look through the code to understand how it works.

For example to create a device you need to call /api/device/add with device JSON object.