Specify Response Format
The Userstack API can deliver API results either in JSON (default) or XML format. To change the response format, append the output parameter to your API request URL and set it to json or xml. Error responses are always JSON.
Example API request - JSON:
https://api.apilayer.net/userstack/detect?access_key=YOUR_ACCESS_KEY&ua=Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_14_0)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/71.0.3578.98%20Safari/537.36&output=jsonExample API request - XML:
https://api.apilayer.net/userstack/detect?access_key=YOUR_ACCESS_KEY&ua=Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_14_0)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/71.0.3578.98%20Safari/537.36&output=xmlAPI response: To see the API response in both formats, go to the API Response section of Getting Started.
Specify Response Fields
API responses can be large, especially for Bulk Lookup requests. The fields parameter lets you request only certain parts of the API response. Separate multiple names with commas.
Examples:
fields=main // general fields only: "ua", "type", "brand", "name" and "url"
fields=brand // only the general "brand" field
fields=os // the complete "os" module
fields=device.name // only "name" inside the "device" module
fields=os.name,device.name // "name" inside "os" and "name" inside "device"Names are case-sensitive. Unknown names are skipped. If none of the names is valid, the API returns 400 with code 301 (invalid_fields).
Example API request:
https://api.apilayer.net/userstack/detect?access_key=YOUR_ACCESS_KEY&ua=Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_14_0)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/71.0.3578.98%20Safari/537.36&fields=type,device.nameExample API response:
{
"type": "browser",
"device": {
"name": "Mac"
}
}As you can see above, the API returns only the fields specified in the request, which reduces the size of the API response and speeds up your application.
Enable Legacy Format
For customers moving from the former UserAgent API, Userstack can deliver API results in a legacy format identical to the former response structure. To enable the legacy format, append the legacy parameter to your API request URL and set it to 1.
Example API request:
https://api.apilayer.net/userstack/detect?access_key=YOUR_ACCESS_KEY&ua=Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_14_0)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/71.0.3578.98%20Safari/537.36&legacy=1Example API response:
{
"data": {
"ua_type": "Desktop",
"os_name": "macOS 10.14 Mojave",
"os_version": "",
"browser_name": "Chrome",
"browser_version": "71.0.3578.98",
"engine_name": "WebKit/Blink",
"engine_version": ""
}
}