The Anti-bot Solution to Scrape Everything? Get Your Free API Key! 😎

How to Set Postman User Agent

November 24, 2023 · 7 min read

Postman's default user agent string can sometimes be identified as bot-like, potentially leading to blocks if not overridden.

In this tutorial, you'll learn to set a custom user agent in Postman and avoid getting blocked. We'll also take this from the request to the collection level, including user agent rotation. Let's get started!

Understanding the User Agent in Postman

Every browser (client) presents an HTTP header to the server during each request. This header serves as a scannable entry point containing information about the client, including the UA string. 

A user agent string tells the server where a request comes from and usually conveys request source information, including the **browser version, operating system, and render engine version. This is how a server tells a bot apart from a legitimate browser.

For an in-depth look at HTTP headers in web scraping, including user agents, see ZenRows's guide on common HTTP headers for web scraping.

The built-in Postman runtime UA usually looks like this:PostmanRuntime/7.35.0. When used to make frequent requests, such as those from scrapers, a server can flag it as a bot. 

Fortunately, you can customize the default Postman user agent to scrape a website without getting blocked.

Setting a Custom User Agent in Postman

So, how can you change the default Postman user agent and set a custom one? You'll learn the step-by-step process in this section. 

We'll use the Postman desktop app in this article. So download and install a compatible version from the Postman download page if you've not already done so.

Step 1: Prepare Your Workspace

Since we'll approach the process from the request level to the collection level, you want to start by creating a collection in Postman. 

A Postman collection is a group of requests you can run individually or simultaneously. For instance, you can execute posts and get requests together as a collection. 

Even if you're only sending one request at the moment, prefer to put it in a collection so you can add more requests as you scale.

To begin, open the Postman desktop app and click the Workspaces dropdown at the top-left. Then, select Create Workspace.

Postman workspaces option
Click to open the image in full screen

You'll see a few template options in the left sidebar. Ignore those since you don't need them for now. Click “Next” to customize your workspace. 

Type a descriptive name (ZenRows Postman UA Test in this case) in the “Name” field in the left sidebar. The “Summary” field is optional, but you can still include a description depending on your choice. 

Select an appropriate accessibility option under “Who can access your workspace?”

Click “Create” once satisfied.

workspace_creation_final
Click to open the image in full screen

After creating the workspace, you can immediately start making requests. But don't jump right on that yet. 

Postman will prompt you to create a collection. Click “Create Collection” in the left sidebar.

Alternatively, you can go to the cross (+) icon at the top-left and select “Blank collection” to create a Postman collection. Either method works.

postman_collection_creation_phase
Click to open the image in full screen

Name your Postman collection by placing your cursor on the collection name field (Testing Custom UA in this case). Then, type a description in the optional summary box below this field. 

collection_name_and_description_final
Click to open the image in full screen

You're all set and ready to start creating requests in your collection! But you need to customize the UA in the request header first. 

So, where's the request header user agent in Postman? 

Let's dig further in the following section!

Step 2: Access the Request Header Settings

You need to access the request header settings before setting a Postman user agent. To achieve this at the request level, you must create a request. 

Right-click the collection name and select “Add request”.

postman_first_request
Click to open the image in full screen

To rename the new request, right-click it and select “Rename”. 

rename_request_option_postman
Click to open the image in full screen

Then, type a descriptive name in the field provided (UA-Get-Test in this case).

postman_rename_request
Click to open the image in full screen

Click the request to select it. Look to the top of the “GET” field, and you'll see the request name appended to your collection name with a trailing forward slash (Testing Custom UA/UA-Get-Test). 

You can also change the request type by clicking the “GET” dropdown and selecting the appropriate request from the options. But we'll stick to the GET request in this tutorial.

Go to “Headers” below the query box to access the request header settings. Once in the “Headers” section, you'll see a Key/Value pair table where you can input strings, including a user agent, for your request header.

Step 3: Set Up a Custom User Agent for a Single Request

Setting a UA at the request level is handy when you want individual requests to use separate user agents.

After you've accessed the “Headers” settings, type “User-Agent” in an empty “Key” box inside the table. Click the “User-Agent” option when it pops. 

postman_user_agent_setting
Click to open the image in full screen

User agents vary, depending on the use case. But prefer to choose from the best user agents for web scraping. Feel free to analyze what your chosen user agent means from UserAgentString

We'll use the following user agent in this case. 

Example
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Next, paste the user agent string in the “Value” box.

postman_user_agent_value
Click to open the image in full screen

You've now changed the Postman default user agent to a custom one. 

How can you verify this? 

Step 4: Verify and Test the Custom User Agent

The first step to verifying that the added user agent works is to check the default UA. 

To do this, untick the “User-Agent” checkbox in the “Headers” section. This removes the custom user agent and defaults to Postman's UA.

Go to the “GET” box and type your target URL. Ensure you append “user-agent” to the URL using a forward slash like this: targetURL/user-agent (https://httpbin.io/user-agent in this case)

Click “Send” at the right, and you should see the default Postman runtime user agent in the response body:

postman_default_user_agent
Click to open the image in full screen

Now that you've confirmed the default user agent, it's time to verify if your custom user agent overrides it. Check the “User-Agent” checkbox in the “Headers” section to activate your custom UA. Then, click “Send” again to confirm.

The request should return your custom Postman user agent as shown:

postman_custom_user_agent_in_response_body
Click to open the image in full screen

It's that easy! You've successfully added a custom user agent to a single request in Postman. What if you want to apply this to a collection such that all the requests in that collection share the same user agent?

Step 5: Apply a Custom User Agent to a Collection

When you add a custom user agent to a collection, all the requests in that group will share it, making your user agent configuration more consistent.

It means you can run the entire collection at once or execute individual requests without worrying about adding a custom Postman UA at the request level.

To apply a custom user agent to a collection, click the collection in the left sidebar. 

Then, go to “Pre-request Script” at the top of the Postman scripting section. Type the following Postman script in the empty code field and press “CTRL + S” (“Command + S” for Mac) to save the changes:

Terminal
pm.request.headers.add({ 
    key: 'User-Agent', 
    value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' 
    });

The script placement should look like this in Postman:

custom_ua_script_postman
Click to open the image in full screen

That's not all. You want to verify if the collection uses your custom Postman user agent. Uncheck the “User-Agent” box in the request Headers or delete this field from each request under your collection and run them individually using the same URL format. 

Each should return the custom user agent added to that collection without explicitly adding it at the request level.

Your custom user agent script works if each request returns the sample response below.

postman_collection_user_agent_verification
Click to open the image in full screen

All requests now share a similar user agent. Pat yourself on the back for this achievement. But it's still only a matter of time before the server detects and flags the frequent requests from this user agent. 

How can you prevent this? Rotate your user agents!  

How to Rotate User Agents in Postman

Rotating your user agents is a potent way to avoid getting blocked. This way, you can split the traffic between different clients at intervals. The logic is to get a list of user agents, catch their index, and feed them to the previous script for rotation.

Modify the previous Postman script (click your collection and go to “Pre-Request Script”):

Example
const userAgents = [
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
  'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
  // Add more user agents as needed
];

// Initialize a global scope counter to keep track of the current user agent
if (!pm.globals.has('userAgentCounter')) {
    pm.globals.set('userAgentCounter', 0);
}
 
// Get the current user agent index from global variables
let currentIndex = pm.globals.get('userAgentCounter');
 
// Set the "User-Agent" header for the current request
pm.request.headers.add({
  key: 'User-Agent',
  value: userAgents[currentIndex % userAgents.length],
});
 
// Update the index for the next request
pm.globals.set('userAgentCounter', (currentIndex + 1) % userAgents.length);

Test the user agent rotation script by running each request in your collection without specifying individual user agents. The UA string will now rotate per request. 

For a diverse range of user agents, we've utilized selections from this list of the best user agents for web scraping.

You're now ready to scrape or test on the go without getting blocked due to a faulty or bot-like user agent. Congratulations!

Frustrated that your web scrapers are blocked once and again?
ZenRows API handles rotating proxies and headless browsers for you.
Try for FREE

Troubleshooting Common Issues

Setting a Postman user agent comes with its challenges. Let's see how you can troubleshoot these common issues. 

Invalid New Line Character

An invalid new line character or an unsupported character error are the most common issues you might encounter while setting a Postman user agent at the request level. 

This is usually due to extra spaces, line breaks, or characters you've picked while copying and pasting the user agent in the “Value” box. If this happens, clear the “User-Agent” value and type it manually instead.

Syntax Errors

Syntax errors in the user agent script at the collection level can also frustrate your effort. Ensure you thoroughly debug the user agent script by checking for missing or unwanted quotes, commas, slashes, and parentheses. Generally, ensure your user agent string doesn't have any formatting issues. 

Access Restrictions

Permission restrictions can happen if you share a collection with a team and don't yet have the required access to modify it. Ensure you have modification permission before adding a user agent in Postman. You might want to reach out to your teammates to grant you access.

Conclusion

Now that you know how to avoid blocks by setting a custom Postman user, you've crushed your basic scraping enemy. 

As a quick recap, you've seen the importance of changing the default Postman user agent, including how to set one at the request and collection levels. Then, we wrapped it up with a user agent rotation in Postman to keep your scraping ball rolling.

Did you find the content helpful? Spread the word and share it on Twitter, or LinkedIn.

Frustrated that your web scrapers are blocked once and again? ZenRows API handles rotating proxies and headless browsers for you.
Try for FREE

The easiest way to do Web Scraping

From Rotating Proxies and Headless Browsers to CAPTCHAs, a single API call to ZenRows handles all anti-bot bypass for you.