# 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.
This section deals with usage of the DeviceAtlas Cloud API.
## Client Side Library - Apple Device Identification ##
In addition to the server-side API, an optional client-side Javascript library
is available. This library is important for two reasons:
1. It facilitates identification of Apple devices. Apple devices are _not_
identifiable using only HTTP User-Agent data.
2. It allows for the collection of dynamic or changing properties.
When the client-side library is embedded in a web page it collects additional
properties from the client's web browser. This data is then sent back to the
server and must be passed to the DeviceAtlas Cloud Client along with the HTTP headers.
The combination of the client data and the server side data allow for accurate
identification of Apple devices.
The client-side library may be included on a webpage by adding the following
snippet:
```Javascript
```
By default, the client-side library returns the data via a cookie. If this is
present in the `HttpRequest` object it will be automatically used.
Alternatively, the client data may be returned via AJAX and passed to the server
side API manually.
For additional information, please see the [Client Side Library](https://docs.deviceatlas.com/apis/clientside/latest/README.ClientSide.html) documentation.
### Basic Usage ###
The DeviceAtlas Cloud Client API can be used as follows:
How to import the Cloud Client API.
```csharp
using Com.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_KEY);
```
If you are using the API within a web context, create an instance of the
client web wrapper.
```csharp
ClientWeb client = ClientWeb.GetInstance();
client.SetLicenceKey(LICENCE_KEY);
```
If you are using the API within a web context in a .NET Framework project,
create an instance of the client framework web wrapper.
```csharp
ClientWebFramework client = ClientWebFramework.GetInstance();
client.SetLicenceKey(LICENCE_KEY);
```
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;
}
```
#### 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...
}
```
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 2024. All Rights Reserved. _
_ https://deviceatlas.com _