User Agent API

User Agent API

Detect any browser, device & OS from user agent strings and generate new ones randomly.
Free Plan $0.00 Monthly Subscribe
10,000 Requests / Monthly
Free for Lifetime
No Credit Card Required
MOST POPULAR
Starter Plan $7.99 Monthly Subscribe
60,000 Requests / Monthly
Standard Support
Ultra-fast and reliable
Competitive price
Pro Plan $29.99 Monthly Subscribe
300,000 Requests / Monthly
Standard Support
Ultra-fast and reliable
Competitive price
Custom Plan Volume Monthly Contact Us
Any requests volume you need
Ultra-fast and reliable
Competitive price

User Agent API is a simple but essential tool that provides an easy way to detect devices like mobile phones, tablets and their capabilities by parsing (browser/HTTP) user agent strings.

User Agent API lets you reliably identify if the user agent is;

  • a mobile phone, a tablet or a PC based device, or
  • A device which has touch capabilities - meaning it has a touch screen on it

How do I use the User Agent API?

Parsing the User Agent Strings

There are some pieces of key information that give you the hint of identifying the visitors access point such as their browser, device or operating systems on different platforms in the market. For example:


{
    "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36",
    "type": {
        "mobile": false,
        "tablet": false,
        "touch_capable": false,
        "pc": true,
        "bot": false
    },
    "browser": {
        "name": "Chrome",
        "version_major": 85,
        "version": "85.0.4183"
    },
    "os": {
        "name": "Windows",
        "version_major": 10,
        "version": "10"
    },
    "device": {
        "name": "Other",
        "brand": null,
        "model": null
    }
}

Generating Random User Agent Strings

We've all been there. We all needed to scrape some remote sites and needed to generate a valid random user-string for each and every request we make. This may be troublesome; with a limited user-agent string database a remote website would easily identify your fingerprint and block you.

This is an extensive database of (325.000+ user agent strings) user-agent strings which is quickly accessible with a simple endpoint. We offer filtering the random results with many parameters such as operating system, device type and browser.

See the following example calling the endpoint with a cURL command


curl --location --request \
GET 'https://api.apilayer.com/user_agent/generate?desktop=true&linux=true' \
--header 'apikey: YOUR API KEY'

This code will generate a response like the followings:


{
    "ua": "Mozilla/5.0 (X11; Ubuntu; Linux i686 on x86_64; rv:47.0) Gecko/20100101 Firefox/47.0",
    "type": {
        "mobile": false,
        "tablet": false,
        "touch_capable": false,
        "pc": true,
        "bot": false
    },
    "browser": {
        "name": "Firefox",
        "version_major": 47,
        "version": "47.0"
    },
    "os": {
        "name": "Ubuntu",
        "version_major": null,
        "version": null
    },
    "device": {
        "name": "Other",
        "brand": null,
        "model": null
    }
}

Please note that the generated user-agent string is automatically parsed for convenience purposes and it will return a unique Linux-based browser user-agent string each time it is executed.

All possible parameters for generating an endpoint is as follows:

  • linux: true/false
  • windows: true/false
  • mac: true/false
  • android: true/false
  • chrome: true/false
  • ie: true/false (Internet Explorer)
  • firefox: true/false
  • mobile: true/false
  • desktop: true/false
  • tablet: true/false

What is the benefit of using User Agent API?

Screen sizes and operating systems may vary, but your user experience shouldn’t. You are sitting on your desk, developing a product with a brilliant team that may reach thousands of users but you can’t afford losing them just because you didn’t optimize your service according to your audience.

Using the User Agent API will provide this opportunity to get to know your visitors as well as some other benefits, not limited to those;

  • Targeting your audience by suggesting any additional services and experiences fitting the ecosystem they belong to. For example; an iPhone user may fall into one of the offerings you have.
  • Guiding them to special promotions you prepare for the new version of their device
  • Planning and configuring your services for the majority of visitors for the next phase

User Agent API Reference

This API is organized around REST. Our API has predictable resource-oriented URLs, accepts form-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.

Just Getting Started?

Check out our development quickstart guide.

Authentication

User Agent API uses API keys to authenticate requests. You can view and manage your API keys in the Accounts page.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

All requests made to the API must hold a custom HTTP header named "apikey". Implementation differs with each programming language. Below are some samples.

All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

Endpoints

Generates a random User Agent with desired parameters

Parameters

android (optional)

If set to true, generates Android user agents

Location: Query, Data Type: string

chrome (optional)

If set to true, generates Chrome Browser user agents

Location: Query, Data Type: string

desktop (optional)

If set to true, generates Desktop Device user agents

Location: Query, Data Type: string

firefox (optional)

If set to true, generates Firefox user agents

Location: Query, Data Type: string

ie (optional)

If set to true, generates Internet Explorer user agents

Location: Query, Data Type: string

linux (optional)

If set to true, generates Linux user agents

Location: Query, Data Type: string

mac (optional)

If set to true, generates Mac user agents

Location: Query, Data Type: string

mobile (optional)

If set to true, generates Mobile Device user agents

Location: Query, Data Type: string

tablet (optional)

If set to true, generates Tablet Device user agents

Location: Query, Data Type: string

windows (optional)

If set to true, generates Windows user agents

Location: Query, Data Type: string

** A word enclosed with curly brackets "{ }" in the code means that it is a parameter and it should be replaced with your own values when executing. (also overwriting the curly brackets).
Returns

Below is a sample response from the endpoint


If you wish to play around interactively with real values and run code, see...

Parses User Agent String provided in the query

Parameters

ua (required)

URLEncoded User Agent String

Location: Query, Data Type: string

** A word enclosed with curly brackets "{ }" in the code means that it is a parameter and it should be replaced with your own values when executing. (also overwriting the curly brackets).
Returns

Below is a sample response from the endpoint


If you wish to play around interactively with real values and run code, see...

Parses User Agent String in the HTTP Raw Body

Parameters

body (required)

User Agent String

Location: Body, Data Type: string

** A word enclosed with curly brackets "{ }" in the code means that it is a parameter and it should be replaced with your own values when executing. (also overwriting the curly brackets).
Returns

Below is a sample response from the endpoint


If you wish to play around interactively with real values and run code, see...

Rate Limiting

Each subscription has its own rate limit. When you become a member, you start by choosing a rate limit that suits your usage needs. Do not worry; You can upgrade or downgrade your plan at any time. For this reason, instead of starting with a larger plan that you do not need, we can offer you to upgrade your plan after you start with "free" or "gold plan" options and start using the API.

When you reach a rate limit (both daily and monthly), the service will stop responding and returning the HTTP 429 response status code (Too many requests) for each request with the following JSON string body text.

{
"message":"You have exceeded your daily\/monthly API rate limit. Please review and upgrade your subscription plan at https:\/\/apilayer.com\/subscriptions to continue."
}

A reminder email will be sent to you when your API usage reaches both 80% and 90%, so that you can take immediate actions such as upgrading your plan in order to prevent your application using the API from being interrupted.

You can also programmatically check your rate limit yourself. As a result of each request made to the APILayer, the following 4 fields provide you with all the necessary information within the HTTP Headers.

x-ratelimit-limit-month: Request limit per month
x-ratelimit-remaining-month: Request limit remaining this month
x-ratelimit-limit-day: Request limit per day
x-ratelimit-remaining-day: Request limit remaining today

You can contact our support unit if you need any assistance with your application regarding to handle the returned result by looking at the header information.

Error Codes

APILayer uses standard HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate a clientside error, which means that failed given the information provided (e.g., a missing parameter, unauthorized access etc.). Codes in the 5xx range indicate an error with APILayer's servers (normally this should'nt happen at all).

If the response code is not 200, it means the operation failed somehow and you may need to take an action accordingly. You can check the response (which will be in JSON format) for a field called 'message' that briefly explains the error reported.

Status Code Explanation
400 - Bad Request The request was unacceptable, often due to missing a required parameter.
401 - Unauthorized No valid API key provided.
404 - Not Found The requested resource doesn't exist.
429 - Too many requests API request limit exceeded. See section Rate Limiting for more info.
5xx - Server Error We have failed to process your request. (You can contact us anytime)

You can always contact for support and ask for more assistance. We'll be glad to assist you with building your product.

Reviews

5.00
  • Review rating
  • Review rating
  • Review rating
  • Review rating
  • Review rating
API rating
Joginder Singer
3 weeks ago

Joginder Singer

  • Review rating
  • Review rating
  • Review rating
  • Review rating
  • Review rating

Very good service sir ji