# 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 ###
In addition to the properties from the data file, properties can be gathered from
the client's browser and used both on the client side and on the server side.
It is strongly recommended to use the Client-side component when using the DeviceAtlas
Cloud API within a web application in order to correctly identify iOS devices.
The client side resource (https://cs-cdn.deviceatlas.com/dacs.js)
must be included on your webpage in order for it to detect the client side properties.
The contents of this cookie are automatically detected by the API.
Please click [here](https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html) for
more information.
### 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 headers = new Dictionary();
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 _