When the GeotabApi object has been set up, the first call to a method will trigger the callback to get the credentials. Once the credentials have been entered by the user, the authenticationCallback will be called with the entered credentials. Then the original method result will then be retrieved. After this method has been called, the server, database, username, and session are stored in localStorage.
The following example demonstrates how to use the GeotabApi object to request the location of a vehicle.
The Call method is used to “Call” any of the APIs that the MyGeotab SDK provides. It takes 4 arguments:
The API method that is being called. For example, “Get” or “GetCountOf”. See the API reference for the full set of methods.
The parameter object that the API method expects. For example:
The function that will be called back when the API call succeeds. The callback function has a single argument called “result” that will contain any results returned by the API call.
The function that will be called back should the API call fail. The callback function has a single argument that will contain error information.
The GeotabApi object is designed to be stateless. The main reason for this is that a call could fail at any point due to session expiry or the database moving. The authenticationCallback will automatically be called when this situation is detected. The application will then prompt (or read from file etc.) for the required credentials. The call that was being attempted will resume when new credentials are received. This also means that there is no concept of being “logged in” or “out” of the server.
Creating a JSONP request is similar to creating a HTTP GET request — but with one minor change. An additional parameter that specifies the callback in the requested URL will be required to be passed as follows:
The response will be in the following format with your current version number:
When the examples are downloaded, the GeotabApi object has an option to use JSONP requests. In this way the examples can be run without placing them on a Web server.