Code Samples
C# Samples
Get Messages for Device
This sample loads the last 1,000 messages for a specified device using a user name and password to authenticate.
using System;
using System.Collections.Generic;
using System.Net;
// use NuGET to add Json.NET library
using Newtonsoft.Json;
namespace ApiDemo
{
class Program
{
private const string serverUri = "<API_URL>";
private const string username = "user@domain.com";
private const string password = "mypassword";
private const string tenantCode = "1234";
private const string deviceId = "<DEVICE_ID>";
static void Main(string[] args)
{
string resourceUrl = String.Format("/V2/{0}/devices/{1}/momessages", tenantCode, deviceId);
List<MoMessage> moMessages = Get<List<MoMessage>>(resourceUrl);
foreach (var moMessage in moMessages)
Console.WriteLine("{0} {1}", moMessage.SentFromDevice, moMessage.Message);
}
private static T Get<T>(string resourceUrl)
{
WebClient webClient = new WebClient();
// pass username and password
webClient.Credentials = new NetworkCredential(username, password);
webClient.BaseAddress = serverUri;
string json = webClient.DownloadString(resourceUrl);
T data = JsonConvert.DeserializeObject<T>(json);
return data;
}
#region Models
public class MoMessage
{
public EmergencyState EmergencyState { get; set; }
public string Message { get; set; }
public string MessageId { get; set; }
public string MessageType { get; set; }
public Position Position { get; set; }
public DateTime ReceivedAtServer { get; set; }
public string Recipients { get; set; }
public DateTime SentFromDevice { get; set; }
public int SequenceNumber { get; set; }
public Dictionary<string, string> Properties { get; set; }
public List<ContainingGeofence> ContainingGeofences { get; set; }
public string MimeType { get; set; }
public string Filename { get; set; }
public string ETag { get; set; }
}
public class Position
{
public double? Latitude { get; set; }
public double? Longitude { get; set; }
public DateTime? GpsTimestamp { get; set; }
public double? Speed { get; set; }
public double? Heading { get; set; }
public double? Altitude { get; set; }
public LocationSourceType LocationSource { get; set; }
public string Accuracy { get; set; }
}
public class ContainingGeofence
{
public string GeofenceId { get; set; }
public string GeofenceName { get; set; }
}
public enum LocationSourceType
{
Gps, Glonass, Doppler, Unknown, DGpsLt10m, GnssGt10m, AndroidLocationService,
iOSLocationService, Beacon, BDAS, Beidou, Galileo, UserProvided
}
public enum EmergencyState
{
None, Emergency, EmergencyCancel, NotSpecified
}
#endregion
}
}Get Device Information
This sample loads device information using an API key to authenticate.
PHP Sample
Get Messages for Device
This sample loads the last 1,000 messages for a specified device using a user name and password to authenticate.
Python Samples
Get Device Information
This sample loads device information using an API key to authenticate.
Get Messages for Device
This sample loads the last 1,000 messages for a specified device using a user name and password to authenticate.
This sample loads the last 1,000 messages for a specified device using an API key to authenticate.
Last updated

