Przejdź do głównej zawartości

I'm programming in Python. I have the geotab library. I need to know what command or set of commands would allow me to query the API to get the last known latitude/longitude of our vehicles.

SChav-2031
Oryginalny plakat

I don't need the entire history. I've also seen reference on the website for querying the latest latitude/longitude and speed, and although sounding promising, it was not really that. I'm reaching out because my frustration with Geotab support is overflowing and I'm seeking your all's assistance!

Dołącz do rozmowy

Aby odpowiedzieć na ten post i uczestniczyć w dyskusjach społeczności Geotab, musisz być zalogowany.

10 Replies

Hey @SChav-2031​,

 

This is in the API Runner which is JS but you should be able to convert this to Python pretty easily. For your use case, you'll need to do this in a multicall and do 1 per device you have.

 

Let me know if you have any questions!

 

EDIT: Sorry I didn't see that you wanted speed too. That's actually a little easier but the API request takes a little longer. I'd just use DeviceStatusInfo and get it for all of your vehicles. Here's an example.

 

Thanks,

Tucker

SChav-2031
Oryginalny plakat

Speed was just an example. I mostly need the identifier, lat/lon and to know it's the most recent location. I have never converted JS to Python - seems to be finicky. I can't believe they have a whole Python geotab library with basically no documentation. <oh well>

SChav-2031
Oryginalny plakat

@Tucket_BA - Thank you, I've expanded my knowledge, but I can't quite get the syntax in Python. I have been programming in Python for several years, but this is the first attempt to call an API in this method.

 

Any other Python examples or experiences will be appreciated.

From what I understand you can just get a LogRecord with a fromDate in the future and it will return the latest one, so for example:

fromDate = datetime(2050, 1, 1) logRecord = api.get('LogRecord', search={'deviceSearch':{'id':'b89'}, 'fromDate':fromDate}) print(logRecord)

The logRecord array should have 0 or 1 items

SChav-2031
Oryginalny plakat

Thank you so much for your answer! It seems that I'm very close to querying via api for the exact data I require. Another question for you - I am aware of our asset numbers, ie, the actual numbers we identify the unit with, however, on this example and on data I've queried has an id number. I'm wondering how one associates the asset number with the id number other than hovering over the asset number and writing down the id numbers, please.

Thank you again!!

 

Respectfully,

STEVE CHAVEZ

System Administrator III

 

Hey @SChav-2031​,

 

You can search by different parameters besides the ID. If you have the asset name or another designation on the device, you can use that as well. Here are the parameters you can use on a typical DeviceSearch.

SChav-2031
Oryginalny plakat

I want to thank you all for your help!! I'm going to continue - I am using: api.get('DeviceStatusInfo', resultsLimit=1, search={'deviceSearch':{'asset':'S003204'}}) two times in a row and one time returns (in my window) four lines and the second time 15 lines. As you can see, I'm searching for an asset, it returns id b4E, but when I hover on S003204 it shows b15. I need help. *** I guess my issue is that I cannot find where to associate an id with our asset number. ***

This is what I would do to get a device id by name:

devices = api.get('Device', search={'name':'S003204'})

Alternatively, you can go into geotab, click on an asset, and its id will appear in the address bar. From what I've seen if you have bad parameters you won't get an error - they will just be ignored, so it's likely that if you took out the search={} from your call it will have the same results.

 

If you look at the reference for the DeviceStatusInfoSearch object, under DeviceSearch it says the options are to search by Id or Groups, so you'll likely need to fetch the id first from the name, and then use that in DeviceStatusInfo:

api.get('DeviceStatusInfo', resultsLimit = 1, search={'deviceSearch':{'id':'b15'}})

 

SChav-2031
Oryginalny plakat

Mlani_567 - you have been a great help!!

My larger problem is that the api documentation is making little sense to me. Feels like it runs in circles. Any words of wisdom would be appreciated.

Here's my next question. I know the name of the group I need to look up and I think I know the id of that group. Those happens to be “Operations Supervisors” and group id of “b287E”. Would there be a way to “api get” the group id stated above that would return a list of all the IDs or names in that group?

All of this is because I've been tasked with placing all of our vehicles from a certain group on a google earth map. My thinking is that I need the id of the group. Hopefully this give me a list of either IDs or Names with which I can query further to get latitude/longitude data. Again, I'm at your all's good graces.

 

Respectfully,

STEVE CHAVEZ

System Administrator III

 

Once you get the hang of it it'll get easier. It's a lot of learning by trial and error - they just switched the look of their API reference website and I could swear they used to have code samples you could use. That's mostly what I learned from, after that they all follow mostly the same pattern. My understanding is that most objects have a search object with properties that you can filter with (i.e. Device -> DeviceSearch) that is the actual object in search={} (the {}), so the word 'DeviceSearch' is not explicitly specified if you are getting a Device. But you can also use DeviceSearch in other search objects, for example a StatusDataSearch.

 

For example, if you want to retrieve a Device you would use a DeviceSearch object to filter them, and in that there is a Groups property that is an array of GroupSearch objects BUT only allows for an Id. So, the DeviceSearch object would be search={}, and then you'd have a groups property that is an array, search={groups:[]}, and in that array you'd have GroupSearch objects with only ids specified, search={groups:[{'id':'GroupCompanyId'}]}

 

The final product would look like:

devices = api.get('Device', search={'groups':[{'id':'GroupCompanyId'}]}) print(devices)

Hopefully this makes sense and I didn't mispeak.

Good luck,

Nadal masz pytania?