Skip to main content

Assistance with Retrieving Max Road Speed Using MyGeotab API Adapter

JRome-1938
Original Poster

Hello everyone,

I'm currently using the MyGeotab API Adapter to retrieve raw data, specifically through the "appsettings.json" file. However, I've noticed in the data dictionary that this setup doesn't include information on the posted speed limit. Has anyone encountered and solved this issue? Any insights or suggestions on retrieving the max road speed data would be greatly appreciated!

Thank you!

Join the conversation

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

Top Answers

EishiFUN
Community Administrator

Hello @JRome-1938​ ,

 

Thank you for asking your question in our community. There's nowhere in the adapter database that road speed limits are available. In the SDK guide, I see a GetPostedRoadSpeedsForDevice method. That might possibly provide the info you need, but it's not in the API Adapter and you would either have to create your own separate process to retrieve it using the MYG SDK (much easier), or modify the API Adapter to add new functionality (very complex).

 

Let us know if you have any other questions. We are happy to help.

 

Have a good one!

Eishi FUN

9 Replies

EishiFUN
Community Administrator

Hello @JRome-1938​ ,

 

Thank you for asking your question in our community. There's nowhere in the adapter database that road speed limits are available. In the SDK guide, I see a GetPostedRoadSpeedsForDevice method. That might possibly provide the info you need, but it's not in the API Adapter and you would either have to create your own separate process to retrieve it using the MYG SDK (much easier), or modify the API Adapter to add new functionality (very complex).

 

Let us know if you have any other questions. We are happy to help.

 

Have a good one!

Eishi FUN

JRome-1938
Original Poster

Hello Eishi,

I have developed a Python script intended to retrieve the posted speed limits using the

GetPostedRoadSpeedsForDevice

API endpoint. Despite using my login credentials and the specified deviceID, the script repeatedly fails, indicating "invalid login credentials." These credentials work without issue when accessing the main Geotab website.

Could you connect me with someone at Geotab who has successfully used this API? I would appreciate guidance on troubleshooting this issue.

Thank you for your help.

EishiFUN
Community Administrator

Can you post the code you are using and I will see if I can have someone take a look at it

JRome-1938
Original Poster
import requests from datetime import datetime   # Your MyGeotab credentials username = '' password = '' database = ''   # MyGeotab API URL url = "https://my.geotab.com/apiv1"   # Define device ID and date range device_id = 'b37' from_date = datetime(2024, 10, 23, 0, 0, 0).isoformat() + 'Z' to_date = datetime(2024, 10, 23, 23, 59, 59).isoformat() + 'Z'   # Step 1: Authenticate to get a session ID auth_payload = { "method": "Authenticate", "params": { "database": database, "username": username, "password": password }, "id": 1 }   # Make the authentication request auth_response = requests.post(url, json=auth_payload) auth_data = auth_response.json()   if 'result' in auth_data: # Retrieve the session ID after successful authentication session_id = auth_data['result']['credentials']['sessionId']   # Step 2: Prepare payload for GetPostedRoadSpeedsForDevice data_payload = { "method": "GetPostedRoadSpeedsForDevice", "params": { "credentials": { "database": database, "sessionId": session_id }, "deviceId": device_id, "fromDate": from_date, "toDate": to_date }, "id": 2 }   # Step 3: Make the request to get posted road speeds data_response = requests.post(url, json=data_payload) data_result = data_response.json()   # Output the results if 'result' in data_result: for speed in data_result['result']: print(speed) else: print("Error retrieving data:", data_result.get("error", "Unknown error"))   else: print("Authentication failed:", auth_data.get("error", "Unknown error"))  

Here is the script i used to retrieve the posted speed limit using the 'GetPostedRoadSpeedsForDevice'. What programming language is used to retrieve the posted speed limit using the method 'GetPostedRoadSpeedsForDevice' or how can i retrieve the posted speed limit using the method from geotab.

EishiFUN
Community Administrator

I apologize for the delay in getting back to you on this. I have not been able to have much luck finding help for you. I think your best bet is to talk with support about this and they will be able to help you out. I can make a ticket for you if you would like.

 

Sorry we could not help more with this in the community.

You are missing the userName in your credentials object in your 2nd call, it is needed along with the sessionId and database.

There is a python package you can use that handles this for you and might be easier: https://github.com/Geotab/mygeotab-python

EishiFUN
Community Administrator

Thank you LP!

JRome-1938
Original Poster

Hello, are you referring to line 4 where the login information is located? If so, I intentionally left that blank. Have you successfully retrieved the road speed limit using the suggestion mentioned?  

No, I mean your object on line 40. Your 2nd call (not Authenticate but GetPostedRoadSpeedsForDevice).

Yes, I've successfully used this API.

You should first fix the credentials issue above, but after that you'll hit another exception with the way you pass in device_id, it should instead be a deviceSearch object as noted in the documentation you linked. Something like:

"deviceSearch": { "id": device_id }, "fromDate": from_date, "toDate": to_date

 

 

Still have questions?