.NET Framework Examples

Notice from Geotab

On September 17, 2022, the current MyAdmin SDK site will be deprecated, and the MyAdmin SDK will be merged with the Geotab SDK site. Please ensure to update your relevant bookmarks as the site will be inaccessible after this date.

Here are a few examples to help you get started. In addition to the examples below, a sample .NET Framework C# project is available for download.

Example 1

The first example is for a console application that authenticates with the MyAdmin API, retrieves a list of device plans, and looks up the details for a specific device.

static void Main(string[] args)
{
   WebServerInvoker api = new WebServerInvoker(null, 60000) { Url = "https://myadminapi.geotab.com/v2/MyAdminApi.ashx" };

   Dictionary<string, object> parameters = new Dictionary<string, object>
   {
      {"username", "user@geotab.com"},
      {"password", "<password>"}
   };
    
   ApiUser apiUser = api.Invoke("Authenticate", typeof (ApiUser), parameters) as ApiUser;
    
   Guid apiKey = apiUser.UserId;
   Guid sessionId = apiUser.SessionId;

   parameters = new Dictionary<string, object>
   {
      {"apiKey", apiKey},
      {"sessionId", sessionId}
   };
   ApiDevicePlan[] devicePlans =
      api.Invoke("GetDevicePlans", typeof (ApiDevicePlan[]), parameters) as ApiDevicePlan[];

   Console.WriteLine("Device Plans");
   Console.WriteLine("Level\tName");
   foreach (ApiDevicePlan devicePlan in devicePlans)
   {
      Console.WriteLine("{0}\t{1}", devicePlan.Level, devicePlan.Name);
   }


   Console.Write("\n\nDevice Information");


   parameters = new Dictionary<string, object>
   {
      {"apiKey", apiKey},
      {"sessionId", sessionId},
      {"serialNo", "G6XXX0XXXD08"}
   };
   ApiDeviceInstallResult device =
      api.Invoke("LookupDevice", typeof (ApiDeviceInstallResult), parameters) as ApiDeviceInstallResult;


   Console.WriteLine("Device Details:");
   Console.WriteLine("Firmware Version {0}", device.FirmwareVersion);
   Console.WriteLine("Comments: {0}", device.Comments);
   Console.WriteLine("Last Server Communication: {0}", device.LastServerCommunication.ToString());
   Console.WriteLine("Possible Issues: {0}", device.PossibleIssues);


   Console.ReadKey();
}
hYgO1H6JtTzw9PnYR70di qee6D2WRg8LDLKNK8fLu4NV8IfeVqi6PKwvWgtdmujE3aEbIkxCFVC uHMYA3ucEQMllgJjoigtCwuplq09cJ3SI3yBJo76pfJLmfocW5V

Example 2:

The second example demonstrates how to create a support ticket with an attachment.

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


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


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


Guid apiKey = apiUser.UserId;
Guid sessionId = apiUser.SessionId;


parameters = new Dictionary<string, object>
{
    {"apiKey", apiKey},
    {"sessionId", sessionId}
};


// Read the attachment from the disk
FileStream file = File.Open("C:\\attachment.jpg", FileMode.Open, FileAccess.Read);
byte[] attachment = new byte[file.Length];
file.Read(attachment, 0, (int)file.Length);
string contentType = "image/jpeg";


parameters = new Dictionary<string, object>
{
    {"apiKey", apiKey},
    {"sessionId", sessionId},
    {"userEmail", "user@geotab.com"},
    {"file", attachment},
    {"contentType", contentType},
    {"fileName", "attachment.jpg"}
};


string fileToken = api.Invoke("UploadSupportTicketFile", typeof(string), parameters) as string;


parameters = new Dictionary<string, object>
{
    {"apiKey", apiKey},
    {"sessionId", sessionId},
    {"userEmail", "user@geotab.com"},
    {"subject", "API Example"},
    {"description", "This is an example of the API"},
    {"fileToken", fileToken}
};
ApiTicket returnTicket = api.Invoke("CreateSupportTicket", typeof(ApiTicket), parameters) as ApiTicket;


Console.WriteLine("New ticket ID: {0}", returnTicket.Id);
Console.ReadKey();
EgWDMphwSQURQ idSLSQECnCncK6Hgu5bONkpoyjoF2DLcEW 4T0DCMK3lAGV2gyz1JyzQpW772hYW4MZUTRvA4S8aJU1VMygPkRpbWynr2fC0Cus17eXd64XDUdjcwd
a0aJ2Z77M4YeIoA ovsqGn Wf2Y 1cBM4BHhTVFfyqOljpEYDWTl9hwSlhl Ay tX9mZIGYaV4OIUdlzFXfXkzQLSOTAXzGnADlr0fa kgjG2t34 osFP f 6G87k32s