# DeviceAtlas Cloud Client API # DeviceAtlas Cloud is a web service that returns device information such as screen width, screen height, is mobile, vendor, model etc. To see a full list of properties, please visit https://deviceatlas.com/resources/available-properties . This Client API provides an easy way to query DeviceAtlas Cloud. It provides the ability to cache returned data locally to greatly improve performance and has automatic failover should one of the global DeviceAtlas Cloud endpoints become unavailable. As of version 1.2, the Client API is able to leverage data collected by the DeviceAtlas Client Side Component. This data is sent to DeviceAtlas Cloud to augment the data found from the normal HTTP headers and also allows the detection of the different iPhone and iPad models. This section deals with usage of the DeviceAtlas Cloud API. ### Client-side Component ### DeviceAtlas provides an optional client-side JavaScript library for gathering additional properties using Javascript. This library can send the gathered properties back to the DeviceAtlas API running on a web server. The JavaScript properties are then used to augment the regular DeviceAtlas properties and allow for additional capabilities like fine-grained Apple device detection. [Read more...](https://docs.deviceatlas.com/apis/clientside/1.9.1/README.ClientSide.html) ### Basic Usage ### The DeviceAtlas Cloud Client API can be used as follows: How to import the Cloud Client API. ```csharp``` using Mobi.Mtld.DeviceAtlas.Cloud; Get an instance of the API (singleton), set your DeviceAtlas licence key and get the properties. ```csharp``` Client client = Client.GetInstance(); client.SetLicenceKey(LICENCE); Detecting based on a set of HTTP headers: ```csharp``` Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("user-agent", "THE USER AGENT ..."); // add more headers ... // must be inside a try catch block try { /* get the API instance (singleton) */ Client client = Client.GetInstance(); /* set your licence key */ client.SetLicenceKey(licenceKey); /* get device properties - by passing HTTP headers */ Hashtable result = client.GetDeviceDataByHeaders(headers); Hashtable properties = (Hashtable)results[Client.KEY_PROPERTIES]; } catch (Exception ex) { // handle the errors... } Detecting based on a user agent string: ```csharp``` string userAgent = "THE USER AGENT ..."; // must be inside a try catch block try { /* get the API instance (singleton) */ Client client = Client.GetInstance(); /* set your licence key */ client.SetLicenceKey(licenceKey); /* get device properties - by passing a user agent string */ Hashtable result = client.GetDeviceDataByUserAgent(userAgent); Hashtable properties = (Hashtable)results[Client.KEY_PROPERTIES]; } catch (Exception ex) { // handle the errors... } * Use the device properties: ```csharp``` if (properties.ContainsKey("mobileDevice") && properties["mobileDevice"]) { // example 1: Get the screen width for image optimization int displayWidth = properties.ContainsKey("displayWidth")? properties["displayWidth"]: 100; // example 2: Get the device vendor name string vendor = properties.ContainsKey("vendor")? properties["vendor"]: ""; // example 3: Touch screen optimization bool useBiggerIcons = properties.ContainsKey("touchScreen")? properties["touchScreen"]: false; // example 4: Send Geo Location JS to client? bool supportsGeoLocation = properties.ContainsKey("js.geoLocation")? properties["js.geoLocation"]: false; } See the list of all property names here: https://deviceatlas.com/resources/available-properties The availability of a property depends on the device and your licence, before accessing a property always check if it exists in the set or not. #### Proxy #### The following code example shows how to set a WebProxy instance to the API. ```csharp``` // must be inside a try catch block try { /* get the API instance (singleton) */ Client client = Client.GetInstance(); /* set your licence key */ client.SetLicenceKey(licenceKey); /* set your WebProxy instance */ client.SetProxy(proxy); ... } catch (Exception ex) { // handle the errors... } See the list of all property names here: https://deviceatlas.com/resources/available-properties The availability of a property depends on the device and your licence, before accessing a property always check if it exists in the set or not. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved. _ _ https://deviceatlas.com _ <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li class="disabled"><a href="README.html">Cloud Client API</a></li><li><a href="README.Installation.html">Cloud Client API Installation</a></li><li><a href="README.Config.html">Cloud Client API Configuration</a></li><li><a href="README.Examples.html">Cloud Client API Examples</a></li><li><a href="README.ExtraTools.html">Cloud Client API Extra Tools</a></li><li><a href="./ApiDocs/index.html">DeviceAtlas Cloud Client API doc</a></li><li class="divider"></li><li><a href="https://docs.deviceatlas.com/apis/clientside/1.9.1/README.ClientSide.html" target="_blank">DeviceAtlas Client-side Component</a></li></ul></div>