Get your API Token

  1. Signup and login to User-Agent Info
  2. Once logged in, click "Billing" link and get your api token.

How to do device, OS and browser detection in various programming languages

<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
// get api token at https://www.useragentinfo.co/
$token = "your api token";
$url = "https://www.useragentinfo.co/api/v1/device/";

$data = array('useragent' => $useragent);

$headers = array();
$headers[] = "Content-type: application/json";
$headers[] = "Authorization: Token " . $token;

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status != 200 ) {
    die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}

curl_close($curl);

echo $json_response;
?>
    
import json
import requests

token = "your-api-token"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Token {}".format(token)
}
payload = {
    "useragent": "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176"
}
url = "https://www.useragentinfo.co/api/v1/device/"
r = requests.post(url, headers=headers, data=json.dumps(payload))
result = r.json()
    
require 'net/https'
require 'json'
require 'uri'

useragent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
token = 'your api token'

uri = URI.parse("https://www.useragentinfo.co/api/v1/device/")
header = {"Authorization": "Token #{token}"}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri, header)
request.set_form_data({"useragent" => useragent})

response = http.request(request)
puts response.body 
    
curl -X POST 'https://www.useragentinfo.co/api/v1/device/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token {api_token}' \
-d '{"useragent":"Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176"}'

Sample Response:

{
  "device_model":"iPhone",
  "bot":false,
  "browser":"Mobile Safari",
  "device_type":"SmartPhone",
  "browser_version":"5.1",
  "os":"iOS",
  "os_version":"5.1",
  "device_brand":"Apple"
}