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 identifies the client making an HTTP request to a server. It usually contains details about the client’s machine and/or the application making the request. Generally, this header is set by web browsers, HTTP clients, or any software that performs web requests.
This is an example of the User-Agent
string set 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 typically read the User-Agent
header to determine whether the requests they receive originate from a browser or another software.
A common mistake made by web scraping bots is the use of default or non-browser User-Agent
strings. These lead to blocks by anti-bot protection technologies because they can recognize the request as coming from a bot. For additional information, see our guide on user agents for web scraping.
What Is the Postman Default User Agent?
Postman is one of the most popular desktop HTTP clients, used by millions of users worldwide. Like most other HTTP clients, it automatically sets a default User-Agent header on each request. Specifically, you can observe this behavior by examining the auto-generated Postman headers:
As you can see, the Postman default user agent follows this format:
PostmanRuntime/x.y.z
“PostmanRuntime” identifies the Postman application, while “x.y.z” is the current version number.
To verify that the above string is indeed the default Postman user agent, perform a GET request to the httpbin.io/user-agent
endpoint. This API endpoint returns the User-Agent
header of the incoming request, helping you identify the user agent used by any HTTP client.
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
As you can tell, the user agent string used by Postman is quite different from the one set by a browser like Chrome. When servers receive requests with such headers, anti-bot systems are likely to block them.
That occurs because those solutions monitor incoming requests, looking for patterns that indicate bot activity such as unusual user agents. Here is why modifying the default user agent in Postman is so crucial!
How to Change the Postman User Agent
Time to see how to set a custom user agent in Postman.
Set the User Agent on a Single Request
Postman allows you to change the user agent on a single HTTP request by manually specifying a User-Agent
header.
Note: The Postman auto-generated headers cannot be directly modified.
Reach the “Headers” tab and add a new User-Agent
header:
Postman will override the auto-generated default user agent with the value of your User-Agent
header. Keep in mind that HTTP headers are case-insensitive, so you can also call your header user-agent
or with any other case.
Check that the approach works by executing a GET request to the httpbin.io/user-agent
endpoint:
Amazing! The user agent returned by the API matches the custom User-Agent header.
Set the User Agent on an Entire Collection
A Postman collection is a group of API requests that usually share common characteristics, such as the target server or scope. In particular, the endpoints within a collection are likely to have similar configurations. Thus, Postman supports the definition of custom scripts that are executed 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 deal with Postman collections, you must first log in to your account. If you have not done so yet, create a Postman account.
Now, assume you have a collection called “HTTPBin” containing the HTTPBin endpoints organized in folders:
Execute the request for the /user-agent
endpoint, and you will get 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 a JavaScript that Postman executes before running a request in a collection.
Follow the instructions below to create a pre-request script for user agent setting.
Double-click on your collection, reach the “Scripts” tab, and 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 the value of the user agent you want to use, as below:
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 a specific header to the request.
Click the “Save” button to apply the changes.
Execute the request for the /user-agent
endpoint again:
This time, the returned user agent will be the one set in the script and not the default Postman one. Mission complete!
Unset the User Agent
The User-Agent
auto-generated header is optional, and you can actually uncheck it. When unchecked, Postman will no longer send a User-Agent
header.
Verify that by sending a request to the httpbin.io/headers
endpoint, which returns all the headers of the incoming request:
Note that the headers object returned by the endpoint does not include the User-Agent
key.
Note: Unsetting the User-Agent
header is not recommended, as nearly web requests typically include that header.
Implement User Agent Rotation in Postman
Simply replacing the default Postman User-Agent
header with one from a browser may not be sufficient to bypass anti-bot systems. That is especially true if you are sending numerous requests with identical headers from the same IP address.
To reduce the risk of being detected as a bot in Postman, you must vary your requests. A practical approach is to use a different User-Agent
for each request, a technique known as user agent rotation. This method decreases the chances of your requests getting flagged as automated.
In this step-by-step section, you will 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 the rotation chances.
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)];
This is what happens in this line of code:
Math.random()
generates a random number between 0 and 1.- The generated number is then 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 that goes from 0 touserAgents.length - 1
.- The index is used to access 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 the 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 request of the collection will now have a rotating User-Agent
header.
Step #4: Put It All Together
Here is 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 that it works by targeting the httpbin.io/user-agent
endpoint. Execute the requests a few times, and you will see rotating user agents:
Wonderful, 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 is not unique to Postman, but applies to all HTTP client and browser automation tools. 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 to set the User-Agent
header and examined what the default Postman user agent looks like. You learned how to override that value and implement user agent rotation to elude basic anti-bot mechanisms. However, more advanced 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 enough!
For a more complete 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.
No credit card required