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
    6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

Incredible Demos

  • By
    HTML5 download Attribute

    I tend to get caught up on the JavaScript side of the HTML5 revolution, and can you blame me?  HTML5 gives us awesome "big" stuff like WebSockets, Web Workers, History, Storage and little helpers like the Element classList collection.  There are, however, smaller features in...

  • By
    JavaScript Copy to Clipboard

    "Copy to clipboard" functionality is something we all use dozens of times daily but the client side API around it has always been lacking; some older APIs and browser implementations required a scary "are you sure?"-style dialog before the content would be copied to clipboard -- not great for...