User Agent API

The User Agent API provides endpoints to parse and generate user agent strings.

Available endpoints:

(4.4)

From 6,328 users

2,000+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
367ms412ms422ms676ms1270ms

Didn't find what you were looking for? Suggest an improvement


/v2/useragentparse GET

https://api.api-ninjas.com/v2/useragentparse

Parses a user agent string to extract device, operating system, and browser information. All response fields are top-level. Invalid or unrecognized user agents return HTTP 200 with is_valid: false and invalid_reason set; data fields are null in that case.

Parameters

  • useragent  required

    User agent string to parse.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON object with the following top-level fields. On success is_valid is true and all data fields are populated. On invalid user agent is_valid is false, invalid_reason contains the reason, and data fields are null. invalid_reason is always present (empty string when valid).

  • browser_family

    Browser name.

  • browser_version

    Browser version.

  • os_family

    Operating system name.

  • os_version

    Operating system version.

  • device_family

    Device family (e.g. Other, iPhone, Samsung SM-G991B).

  • device_brand

    Device brand.

  • device_model

    Device model.

  • device_type

    One of computer, tablet, or mobile.

  • is_valid

    Whether the user agent passed validation.

  • invalid_reason

    Always present. Empty string when valid; when is_valid is false, describes why the user agent was rejected.

Sample Request Live Demo!

useragent

Try this API endpoint with all available parameters in our API playground

https://api.api-ninjas.com/v2/useragentparse?useragent=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_9_4)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F41.0.2272.104%20Safari%2F537.36

Headers

X-Api-KeyLog in or sign up to get your API Key

Response

JSON

Code Examples

1 2 3 4 5 6 7 # Parse user agent curl -X GET "https://api.api-ninjas.com/v2/useragentparse?useragent=Mozilla%2F5.0%20%28Macintosh%3B%20Intel%20Mac%20OS%20X%2010_9_4%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F41.0.2272.104%20Safari%2F537.36" \ -H "X-Api-Key: YOUR_API_KEY" # Generate user agent curl -X GET "https://api.api-ninjas.com/v1/useragentgenerate?os=windows&browser=chrome" \ -H "X-Api-Key: YOUR_API_KEY"

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.


/v1/useragentgenerate GET

https://api.api-ninjas.com/v1/useragentgenerate

Generates a realistic user agent string based on optional parameters.

Parameters

  • brand  optional

    Device brand (e.g. Apple, Samsung)

  • model  optional

    Device model (e.g. iPhone, Galaxy)

  • os  optional

    Operating system (e.g. Windows, iOS, Android)

  • browser  optional

    Browser name (e.g. Chrome, Firefox, Safari)

Response

A JSON object with the following fields or an error if the request is unsuccessful.

  • user_agent

    A randomly generated user agent string matching the specified criteria.

Generate User Agent Sample Request Live Demo!

brand
model
os
browser

Try this API endpoint with all available parameters in our API playground

https://api.api-ninjas.com/v1/useragentgenerate?os=windows&browser=chrome

Headers

X-Api-KeyLog in or sign up to get your API Key

Generate User Agent Sample Response

JSON