Using in .NET

Overview

The .NET SDK tools provide an easy way to integrate MyAdmin with your own native .NET software. All of the communication to our services is done over HTTPS with data serialized in JSON format. The provided .NET library will automatically handle the JSON serialization and deserialization into MyAdmin objects for you.

MyAdminLib.dll

Including this assembly in your project allows you to interact with our API. It is a convenient “wrapper” around our HTTP/JSON API so that you can worry more about writing code than moving data over the wire. It includes tools to assist with automatically serializing/deserializing JSON, and provides definitions for MyAdmin object classes.

Get the MyAdminLib.dll from the link at the bottom of the page, unzip the DLL and and add a reference to it from your .NET project.

Step 1: Initialization & Authentication

The WebServerInvoker class contains methods that facilitate calling API functions. To access the invoker, include the following in your code:

using MyAdminApiLib.Geotab.MyAdmin.MyAdminApi.ObjectModel

You can now create an instance of the API invoker in your code:

WebServerInvoker api = new WebServerInvoker(null, 60000) {Url = “https://myadminapi.geotab.com/v2/MyAdminApi.ashx”};

An instance of a class that implements the IWebProxy interface can be passed as the first parameter if needed. The second parameter takes a timeout in milliseconds. The recommended timeout value is 60 seconds.

The parameters required by each method are passed using a Dictionary<string, object>. For example, to authenticate with the API, call the Authenticate method passing a valid username and password as follows:

Dictionary<string, object> parameters = new Dictionary<string, object> { { "username", "user@geotab.com" }, { "password", "<password>" } };


ApiUser apiUser = api.Invoke("Authenticate", typeof(ApiUser), parameters) as ApiUser;

This method authenticates with the MyAdmin API and, if successful, returns an ApiUser object. This object contains, among other properties, the UserId (used as the API key for all other methods) and SessionId.

Step 2: Making Calls

Once authenticated, other methods can be called by passing the API key, Session ID, and any other parameters required by the method.

// apiKey and sessionId were obtained from ApiUser object returned by Authenticate
Dictionary<string, object> parameters = new Dictionary<string, object> { { "apiKey", apiKey }, { "sessionId", sessionId }, { "serialNo", "G63XXXXXXXX8" } };


ApiDeviceInstallResult installResult = api.Invoke("LookupDevice", typeof(ApiDeviceInstallResult), parameters) as ApiDeviceInstallResult;

Download

Download MyAdminApiLib.zip.

More Information

For more information, see the .NET examples section.