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
    Create Namespaced Classes with MooTools

    MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does.  Many developers create their classes as globals which is generally frowned up.  I mostly disagree with that stance, but each to their own.  In any event...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    Degradable SELECT onChange

    Whenever I go to Google Analytics I notice a slight flicker in the dropdown list area. I see a button appear for the shortest amount of time and the poof! Gone. What that tells me is that Google is making their site function...

  • By
    MooTools: Set Style Per Media

    I'd bet one of the most used MooTools methods is the setStyle() method, which allows you to set CSS style declarations for an element. One of the limitations of MooTools' setStyle() method is that it sets the specific style for all medias.