Amazing User Agent API with userstack

By  on  

We do our best to design and code websites so that they look and perform the way they should regardless of device or browser, but the truth is we sometimes we need to code for specific device, browser, or crawler. Whether it's a quick hack or a simply wanting to display different content for a given device, you eventually need that information. apilayer has created an amazing api, userstack, to help you!

userstack animation

Quick Hits

  • All you need to do is provide the user agent to get a detailed summary of the user's device
  • The userstack API is free to use
  • Supports multiple output formats (json and xml)
  • Provides bulk lookup as well as single lookup
  • Trusted by ZenDesk, Amazon, Apple, and Lyft
  • Created by apilayer, creators of other amazing APIs like currencylayer, mailboxlayer, eversign, and more

Using userstack

Start by signing up for your free API key at userstack. Once you have your API key, you can start using the simple but very useful userstack API.

All you need to do is send the API key and user agent to the endpoint and you'll get a logical, informative object that describes the user device, browser, and more:

curl https://api.userstack.com/api/detect
    ?access_key=MY_API_KEY
    &ua=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3672.0 Safari/537.36
{  
   "ua":"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3672.0 Safari\/537.36",
   "type":"browser",
   "brand":"Apple",
   "name":"Mac",
   "url":"https:\/\/www.google.com\/about\/company\/",
   "os":{  
      "name":"macOS 10.14 Mojave",
      "code":"macos_10_14",
      "url":"https:\/\/en.wikipedia.org\/wiki\/MacOS_Mojave",
      "family":"macOS",
      "family_code":"macos",
      "family_vendor":"Apple Inc.",
      "icon":"https:\/\/assets.userstack.com\/icon\/os\/macosx.png",
      "icon_large":"https:\/\/assets.userstack.com\/icon\/os\/macosx_big.png"
   },
   "device":{  
      "is_mobile_device":false,
      "type":"desktop",
      "brand":"Apple",
      "brand_code":"apple",
      "brand_url":"http:\/\/www.apple.com\/",
      "name":"Mac"
   },
   "browser":{  
      "name":"Chrome",
      "version":"73.0.3672.0",
      "version_major":"73",
      "engine":"WebKit\/Blink"
   },
   "crawler":{  
      "is_crawler":false,
      "category":null,
      "last_seen":null
   }
}

The returned object provides a wealth of information, parsed and placed into logical sections:

  • device: is_mobile_device is a very useful property to incorporate for your design layouts
  • browser: providing version information
  • crawler: lets you know if it's a webcrawer or bot, and which bot you are

You can provide additional parameters to specify just the information you want returned from the API:

curl https://api.userstack.com/api/detect
    ?access_key=MY_API_KEY
    &ua=...
    &fields=device,browser.version

Like other apilayer APIs, userstack allows you to use JSONP:

curl https://api.userstack.com/api/detect
    ?access_key=MY_API_KEY
    &ua=...
    &callback=MY_FUNCTION_NAME

What I love about apilayer APIs is that they're always simple to use and were constructed for a very specific purpose. What userstack provides is so useful and I can trust it to be accurate and maintained. Give userstack a look -- it's worth your time to get accurate, usable useragent information!

Recent Features

  • By
    Regular Expressions for the Rest of Us

    Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...

  • By
    How I Stopped WordPress Comment Spam

    I love almost every part of being a tech blogger:  learning, preaching, bantering, researching.  The one part about blogging that I absolutely loathe:  dealing with SPAM comments.  For the past two years, my blog has registered 8,000+ SPAM comments per day.  PER DAY.  Bloating my database...

Incredible Demos

  • By
    Fade Images with MooTools LazyLoad

    I recently received an email from a MooTools developer asking a great question about my LazyLoad class: "I'm using your LazyLoad MooTools plugin (which is great, by the way). I have been trying to figure out how to modify it so that once an image scrolls into...

  • By
    Implementing Basic and Fancy Show/Hide in MooTools 1.2

    One of the great parts of MooTools is that the library itself allows for maximum flexibility within its provided classes. You can see evidence of this in the "Class" class' implement method. Using the implement method, you can add your own methods to...