Userparser Loader Gif

User Agent parser API documentation


Last Updated: 19-Apr-2023

This API version is old version, please read the new one Go to new Version

Userparser User Agent Parser API has an incredible user agent look up API for free for 10,000 per month. You want more? you can upgrade anytime.

If you want to parse your users user agent we have a good solution for you you can register and get your API key from your dashboard page then with that API key, you can parse any of your users user agent simply, and easily.

How can you integrate that with your system, Let us help you out step by step in this documentation.

In case if we left unanswered for any question you might ask please let us know it.

API Overview

After getting your uniquely generated hashed API key you can append and use it like this.

  
https://api.userparser.com/1.0/detect?api_key='YOUR_API_KEY';
  

Protect your API key: To prevent unauthorized use of your API key, please make sure to keep your API key private and safe from third parties. In case if you want to reset or change it you can do it in your dashboard page.

Now get your users user agent data, if you use PHP you can get it by just looking up the HTTP_USER_AGENT header.

  
$user_agent = $_SERVER['HTTP_USER_AGENT'];
  

Now to use all the above variables to make the whole new URL.

  
https://api.userparser.com/1.0/detect?ua=YOUR_USER_AGENT&api_key=YOUR_API_KEY
OR
https://api.userparser.com/1.0/detect?ua=$user_agent&api_key=6H8xxxxxxxxxxxxxxxxxxx4B7
  

API Response

Our API response is either through JSON or XML as you want.
We've an optional parameter called format which uses to choose either JSON or XML response. If you don't specify this parameter the API response will be in JSON format (defualt API response is JSON).

JSON Response

  
{
    "info": {
        "status": "success",
        "message": "The user agent was parsed successfully.",
        "ua": "Mozilla/5.0 (Linux; Android 11; SM-A505F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.101 Mobile Safari/537.36"
    },
    "browser": {
        "name": "Chrome",
        "version": "98",
        "fullVersion": "98.0.4758.101",
        "engine": "Blink"
    },
    "operatingSystem": {
        "name": "Android",
        "version": "11"
    },
    "device": {
        "name": "Samsung Galaxy A50",
        "type": "Smartphone",
        "brand": "Samsung",
        "screenResolutionWidth": "1080px",
        "screenResolutionHeight": "2340px",
        "viewportWidth": "412px",
        "viewportHeight": "756px",
        "language": null,
        "isTouchScreen": true,
        "isMobile": true
    },
    "crawler": {
        "isCrawler": false,
        "name": null,
        "owner": null,
        "category": null,
        "url": null,
        "lastSeen": null
    }
}
  

XML Response

  
<response>
<info>
<status>success</status>
<message>The user agent was parsed successfully.</message>
<ua>Mozilla/5.0 (Linux; Android 11; SM-A505F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.101 Mobile Safari/537.36</ua>
</info>
<browser>
<name>Chrome</name>
<version>98</version>
<fullVersion>98.0.4758.101</fullVersion>
<engine>Blink</engine>
</browser>
<operatingSystem>
<name>Android</name>
<version>11</version>
</operatingSystem>
<device>
<name>Samsung Galaxy A50</name>
<type>Smartphone</type>
<brand>Samsung</brand>
<screenResolutionWidth>1080px</screenResolutionWidth>
<screenResolutionHeight>2340px</screenResolutionHeight>
<viewportScreenWidth>412px</viewportScreenWidth>
<viewportScreenHeight>756px</viewportScreenHeight>
<language/>
<isTouchScreen>1</isTouchScreen>
<isMobile>1</isMobile>
</device>
<crawler>
<isCrawler/>
<name/>
<owner/>
<category/>
<url/>
<lastSeen/>
</crawler>
</response>
  

API Error handler

Whenever the API failed to process the request, it gives the reason of the failure in the status and message of the API response.

The response in the status name has an error value in error response.

The response in the message name has the reason of the error response.

General speaking whenever there is error in the request process the status will be return error value. And the message name will have the error reason.

Object Description
status error
message error reason

API Error example

  
{
    "info": {
        "status": "error",
        "message": "Invalid API KEY, please get your valid API key from here [ https://www.userparser.com/dashboard/ ]."
    }
}
 

API Response Objects

Based on your request parameters and our API response data there are more than 24 API response objects.

Object Description
info > status Returns success or error
info > message Returns the message that varies by end-point
info > ua Returns the User Agent provided by you.
browser > name Returns the name of the browser.
browser > version Returns the whole number version of the browser or null.
browser > fullVersion Returns the full version of the browser or null.
browser > engine Returns the Render engine of the browser or null.
operatingSystem > name Returns the name of the operating system or null.
operatingSystem > version Returns the version of the operating system or null.
device > name Returns the name of the device or null.
device > type Returns either TV, Desktop, Tablet, Smartphone or Crawler.
device > brand Returns the Brand name of the device or null.
device > screenResolutionWidth Returns the width of the device screen resolution with px or null.
device > screenResolutionHeight Returns the height of the device screen resolution with px or null.
device > viewportScreenWidth Returns the width of the device viewport screen with px or null.
device > viewportScreenHeight Returns the height of the device viewport screen with px or null.
device > language Returns the language of the browser and most of the time the browser set to defualt Language of the device or null.
device > isTouchScreen Returns true or false.
device > isMobile Returns true or false.
crawler > isCrawler Returns true or false.
crawler > name Returns the name of the crawler or null.
crawler > owner Returns the owner name of the crawler or null.
crawler > category Returns the category of the crawler (search-engine, Marketing, Monitors, sitemap-generator, Scrapers, etc... or null.
crawler > url Returns the URL of the crawler or null.
crawler > lastSeen Returns When was the crawler last seen or null.

API HTTP GET Request Parameters

The API have two required parameters and one another optional parameter.

Object Description
api_key [Required] Your API key, can be found in your dashboard page.
ua [Required] Your users user agent.
format [Optional] Your chosen API response format, either throughJSON or XML format.

Code Examples

You can use our API service in any programming language you want. Some of them

PHP

  
$json_url = "https://api.userparser.com/1.0/detect?ua=YOUR_USER_AGENT&api_key=YOUR_API_KEY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $json_url);
$json_data = curl_exec($ch);
curl_close($ch);
$json_result = json_decode($json_data);

if($json_result->browser->name == "Chrome"){
    echo "Its a Chrome browser.";
}
 

Before sending your user agent to the API, use the built-in PHP function urlencode().

urlencode() is a function in PHP that is used to encode a string into a URL-friendly format. It converts special characters, such as spaces and punctuation marks, into their respective hexadecimal values.

You can use it like this

  
<?php
$urlencoded_user_agent = urlencode($user_agent); // With encoded url like this, your request is safe.
?>
 

Python

  
import requests

json_data = requests.get('https://api.userparser.com/1.0/detect?ua=YOUR_USER_AGENT&api_key=YOUR_API_KEY')

if json_data.json()['browser']['name'] == 'Chrome':
  print ('Its a Chrome browser.');
  

jQuery

 
  $.ajax({
  url: 'https://api.userparser.com/1.0/detect',
  type: 'GET',
  dataType: 'JSON',
  data: {
     api_key: 'YOUR_API_KEY',
     ua: 'YOUR_USER_AGENT'
  },
  success: function(json) {
    if (json.device && json.device.type == 'Smartphone') {
      console.log("It's a Smartphone.");
    }
  }
});
  

Full PHP code example

  
$json_url = "https://api.userparser.com/1.0/detect?ua=YOUR_USER_AGENT&api_key=YOUR_API_KEY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $json_url);
$result = curl_exec($ch);
curl_close($ch);
$json_data = json_decode($result);
if($json_data->info->status == "success"){
    $brawserName = $json_data->browser->name;
    $browserVersion = $json_data->browser->version;
    $browserFullVersion = $json_data->browser->fullVersion;
    $renderEngine = $json_data->browser->engine;
    $osName = $json_data->operatingSystem->name;
    $osVersion = $json_data->operatingSystem->version;
    $deviceName = $json_data->device->name;
    $deviceType = $json_data->device->type;
    $deviceBrand = $json_data->device->brand;
    $screenWidth = $json_data->device->screenResolutionWidth;
    $screenHeight = $json_data->device->screenResolutionHeight;
    $viewportScreenWidth = $json_data->device->viewportScreenWidth;
    $viewportScreenHeight = $json_data->device->viewportScreenHeight;
    $languageDetection = $json_data->device->language;
    $isTouchScreen = $json_data->device->isTouchScreen;
    $isMobile = $json_data->device->isMobile;
    $apiResultMessage = $json_data->info->message;
    $userAgent = $json_data->info->ua;
    $isCrawler = $json_data->crawler->isCrawler;
    $crawlerName = $json_data->crawler->name;
    $crawlerOwner = $json_data->crawler->owner;
    $crawlerCategory = $json_data->crawler->category;
    $crawlerUrl = $json_data->crawler->url;
    $crawlerLastSeen = $json_data->crawler->lastSeen;
}
 

Try the API for free!

10,000 Free API calls :)

If you've question or need technical support please Contact us directly.

Happy coding 😊