Learn how to set, change, and rotate the User-Agent header in Postman to avoid anti-bot detection and improve your HTTP requests.
In this Postman user agent article, you will learn:
- Why you should set the User-Agent header
- What the Postman default user agent looks like
- How to change the user agent in Postman requests
- How to implement user agent rotation in Postman
Let’s dive in!
Why Setting a Custom User Agent Is So Crucial
The User-Agent header serves as an identifier for the client making HTTP requests to web servers. It typically contains information about the client’s operating system and the application used for the request. Web browsers, HTTP clients, and various software applications that perform web requests automatically set this header.
Here’s an example of a User-Agent string generated by Chrome when requesting a web page:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
The User-Agent header of a browser includes several components:
- Mozilla/5.0: Initially used to indicate compatibility with Mozilla browsers, this prefix is now included for broader compatibility.
- Macintosh; Intel Mac OS X 10_15_7: Specifies the operating system (Mac OS X 10_15_7) and platform (Intel Mac).
- AppleWebKit/537.36: Refers to the rendering engine used by Chrome.
- (KHTML, like Gecko): Indicates compatibility with KHTML and Gecko layout engines.
- Chrome/127.0.0.0: Denotes the browser name and version.
- Safari/537.36: Suggests compatibility with Safari.
Servers analyze the User-Agent header to distinguish between requests from browsers versus automated software.
A frequent error made by web scraping bots involves using default or non-browser User-Agent strings. This leads to blocks by anti-bot protection systems that can identify bot traffic. For additional information, see our guide on user agents for web scraping.
What Is the Postman Default User Agent?
Postman stands as one of the most widely-used desktop HTTP clients, serving millions of users globally. Like other HTTP clients, it automatically assigns a default User-Agent header to each request. You can observe this behavior by examining the auto-generated Postman headers:
observe this behavior by examining the auto-generated Postman headers
The Postman default user agent follows this format:
PostmanRuntime/x.y.z
“PostmanRuntime” identifies the Postman application, while “x.y.z” represents the current version number.
To confirm this string is the default Postman user agent, make a GET request to the httpbin.io/user-agent endpoint. This API endpoint returns the User-Agent header of incoming requests, helping you identify the user agent used by any HTTP client.
identify the user agent used
Notice how the user agent returned by the API matches the one set by Postman by default. In detail, the Postman user agent is:
PostmanRuntime/7.41.0
The user agent string used by Postman differs significantly from browser-generated ones like Chrome. When servers receive requests with such headers, anti-bot systems will likely block them.
This occurs because protection solutions monitor incoming requests for patterns indicating bot activity, such as unusual user agents. This is why modifying the default user agent in Postman becomes essential!
How to Change the Postman User Agent
Let’s explore how to set a custom user agent in Postman.
Set the User Agent on a Single Request
Postman enables you to modify the user agent on individual HTTP requests by manually specifying a User-Agent header.
Note: The Postman auto-generated headers cannot be directly modified.
Navigate to the “Headers” tab and add a new User-Agent header:
adding a new user-agent header
Postman will override the auto-generated default user agent with your User-Agent header value. Remember that HTTP headers are case-insensitive, so you can name your header user-agent or use any other case variation.
Verify this approach works by executing a GET request to the httpbin.io/user-agent endpoint:
executing a GET request
Excellent! The user agent returned by the API matches your custom User-Agent header.
Set the User Agent on an Entire Collection
A Postman collection groups API requests that typically share common characteristics, such as target server or scope. Endpoints within a collection often require similar configurations. Postman supports custom scripts that execute before or after each request in a collection.
Let’s see how to use this mechanism to set a custom user agent for all requests in a Postman collection!
To create and manage Postman collections, you must first log in to your account. If you haven’t done so yet, create a Postman account.
Assume you have a collection called “HTTPBin” containing HTTPBin endpoints organized in folders:
HTTPBin endpoints organized in folders
Execute the request for the /user-agent endpoint, and you’ll get the default Postman user agent:
the default Postman user agent
Time to change that by defining a pre-request script that sets a custom User-Agent header. A pre-request script is JavaScript code that Postman executes before running requests in a collection.
Follow these instructions to create a pre-request script for user agent configuration.
Double-click on your collection, reach the “Scripts” tab, and select the “Pre-request” option:
select the “Pre-request” option
In the editor, paste the following code:
pm.request.headers.add({
key: "User-Agent",
value: "<your-user-agent>"
});
Replace the <your-user-agent> string with your desired user agent value:
pm.request.headers.add({
key: "User-Agent",
value: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
});
pm.request.headers.add() is a special function from the Postman API to add specific headers to requests.
Click the “Save” button to apply the changes.
Execute the request for the /user-agent endpoint again:
executing the request again
This time, the returned user agent will be the one set in the script rather than the default Postman one. Mission complete!
Unset the User Agent
The User-Agent auto-generated header is optional and can be unchecked. When unchecked, Postman will not send a User-Agent header.
Verify this by sending a request to the httpbin.io/headers endpoint, which returns all headers of the incoming request:
return of all the headers of the incoming request
Note that the headers object returned by the endpoint doesn’t include the User-Agent key.
Note: Removing the User-Agent header isn’t recommended, as nearly all web requests typically include this header.
Implement User Agent Rotation in Postman
Simply replacing the default Postman User-Agent header with a browser one may not suffice to bypass anti-bot systems. This becomes especially true when sending numerous requests with identical headers from the same IP address.
To minimize bot detection risk in Postman, you must diversify your requests. A practical approach involves using different User-Agents for each request, a technique called user agent rotation. This method reduces the likelihood of requests being flagged as automated.
In this step-by-step section, you’ll learn how to implement user agent rotation in Postman!
Step #1: Retrieve a List of User Agents
Visit a site like WhatIsMyBrowser.com and populate a list of valid user agents:
const userAgents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36 EdgA/127.0.2651.82",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/127.0.6533.107 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14.6; rv:129.0) Gecko/20100101 Firefox/129.0",
// other user agents...
];
Tip: The more real-world user agents this array contains, the better to increase rotation effectiveness.
Step #2: Randomly Pick a User Agent
Use the JavaScript Math API to randomly select a user agent from the list:
const userAgent = serAgents[Math.floor(Math.random() * userAgents.length)];
Here’s what happens in this line of code:
Math.random()generates a random number between 0 and 1.- The generated number is multiplied by the length of the userAgents array.
Math.floor()rounds down the resulting number to the largest integer less than or equal to the source number. The resulting number corresponds to an index from 0 to userAgents.length – 1.- The index accesses a random item from the array of user agents.
- The randomly selected user agent is assigned to a variable.
Step #3: Define the User-Agent Header
Use pm.request.headers.add() to define a User-Agent header with the random userAgent value:
pm.request.headers.add({
key: "User-Agent",
value: userAgent
});
The HTTP requests in the collection will now have a rotating User-Agent header.
Step #4: Put It All Together
Here’s your final Postman pre-request script for user agent rotation:
// a list of valid user agents
const userAgents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.2651.86",
"Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36 EdgA/127.0.2651.82",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/127.0.6533.107 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14.6; rv:129.0) Gecko/20100101 Firefox/129.0",
// other user agents...
];
// randomly extract a user agent from the list
const userAgent = userAgents[Math.floor(Math.random() * userAgents.length)];
// set the random user agent header
pm.request.headers.add({
key: "User-Agent",
value: userAgent
});
Add it to your collection and verify functionality by targeting the httpbin.io/user-agent endpoint. Execute requests multiple times, and you’ll see rotating user agents:
executing requests and seeing the rotation of user agents
Perfect! The returned user agent keeps changing.
Et voilà! You now know how to implement rotating Postman user agent logic.
Further Reading
Changing the default user agent applies to all HTTP clients and browser automation tools, not just Postman. Explore our guides:
- cURL User Agent Guide: Setting and Changing
- Wget User Agent Guide: Setting and Changing
- Python Requests User Agent Guide: Setting and Changing
- Selenium User Agent Guide: Setting and Changing
- Node.js User Agent Guide: Setting and Changing
Conclusion
In this article, you understood why setting the User-Agent header matters and examined what the default Postman user agent looks like. You learned how to override that value and implement user agent rotation to bypass basic anti-bot mechanisms. However, more sophisticated systems will still be able to block your requests. To prevent IP bans, you could use a proxy in Postman, but even that may not be sufficient!
For a more comprehensive solution, try Web Scraper API—a next-generation scraping API you can call from Postman or any other HTTP client. It effectively bypasses anti-scraping and anti-bot measures using built-in features like IP and user agent rotation. Web scraping has never been easier!
Sign up today to start your free trial.