SoftwareTestPilot
API TestingPublished: 11 min read

Postman 401 Unauthorized Error: 8 Causes and Fixes

Getting 401 Unauthorized in Postman? Find the cause in minutes: missing token, unset variable, Bearer typed twice, wrong auth type, expired token, and more.

SoftwareTestPilot
QA Editorial Team
Share:XLinkedInWhatsApp
Postman 401 Unauthorized Error: 8 Causes and Fixes: API Testing article cover, SoftwareTestPilot.com
Postman 401 Unauthorized Error: 8 Causes and Fixes: API Testing article cover, SoftwareTestPilot.com

Short answer

Postman shows 401 Unauthorized when the server did not accept the login details sent with that request. Per RFC 9110, 401 means the credentials were missing or invalid. It is almost never a Postman bug. The fix is to find out what Postman actually sent and make it match what the API expects.

Do this first:

  1. Open the Postman Console (bottom-left of the app, or View > Show Postman Console) and send the request again.
  2. Expand the request and read the Authorization header that went out.
  3. It should usually look like Authorization: Bearer eyJ...: the word Bearer, one space, the token, nothing else.

If that header is missing, shows {{token}}, shows Bearer Bearer, has quotes, or starts with Basic, you have found the cause. The sections below cover each one. Postman explains the Console in its guide to debugging API requests.

How the examples in this guide were produced

Every response in this article is real. On 6 November 2026 we built a small Postman collection with nine requests, one per common mistake, and ran it with Newman 6.2.3, Postman's official command-line runner (see Postman's Newman docs). Newman uses the same request engine as the Postman app, so the auth settings behave the same way.

The target was the free practice API behind the SoftwareTestPilot API Playground. It needs a Bearer token for writes, so POST /products is a good endpoint to break on purpose. You can repeat every step yourself with the same login: qa.tester / Practice@123.

What each mistake returned (real results)

Same endpoint, same body ({"name":"Postman lab","price":10}), eight different auth setups:

#Auth setup in PostmanStatusError code in body
1Auth Type: No Auth401token_missing
2Inherit auth from parent, but {{token}} not set yet401token_invalid
3Login request with the wrong password (practice@123, lower-case p)401"Invalid username or password"
4Valid token, but the required X-Sandbox-Key header left out401token_invalid
5Valid token and X-Sandbox-Key201 Creatednone
6Bearer Token field contains Bearer {{token}}401token_invalid
7Bearer Token field contains "{{token}}" (with quotes)401token_invalid
8Auth Type: Basic Auth with the correct username and password401token_invalid

Only one setup worked. Notice that rows 2, 4, 6, 7 and 8 all give the same error, even though the causes are different. That is why reading the sent header in the Console matters more than reading the error message.

Here is the exact response body for row 1 (no token) and row 2 (unset variable):

// Row 1: No Auth
HTTP 401 Unauthorized
{"error":{"status":401,"code":"token_missing","message":"Missing Bearer token. POST /auth/login first, then send Authorization: Bearer <token>."}}

// Row 2: {{token}} not set
HTTP 401 Unauthorized
{"error":{"status":401,"code":"token_invalid","message":"Token not recognised for this workspace. Use the token from your latest login."}}

Your API's wording will differ, but many APIs follow RFC 6750 and return WWW-Authenticate: Bearer error="invalid_request" when the token is missing and error="invalid_token" when it is wrong or expired. Check the response Headers tab in Postman for that hint.

The 8 causes of a Postman 401, and how to fix each

1. No token was sent

Symptom: no Authorization header in the Console. Why: the request's Auth Type is No Auth, or it inherits from a folder or collection that has No Auth. Fix: open the request's Authorization tab, choose Bearer Token (or whatever your API uses), and add the token. Better: set it once on the collection and leave each request on Inherit auth from parent.

2. The token variable has no value

Symptom: the Console shows Bearer {{token}} as literal text, or the variable is underlined red in the Token field. Why: Postman sends an unresolved variable as plain text. This happens when the wrong environment is selected in the top-right dropdown, the variable lives in a different scope, or you have not run the login request yet. Fix: select the right environment, hover over {{token}} to see its current value and scope, and run login first. Postman's variables guide explains how scopes override each other.

3. The login request itself returns 401

Symptom: 401 comes back from /login or /oauth/token, before any token exists. Why: wrong username, password, client ID or client secret. Passwords are case-sensitive; in our test, practice@123 failed where Practice@123 worked. Fix: check the body type (raw JSON vs form-data vs x-www-form-urlencoded), the Content-Type header, and the exact credentials. This is a credentials problem, not a token problem.

4. The API needs another header as well

Symptom: the Bearer header looks perfect but you still get 401. Why: some APIs also need an API key, tenant ID, subscription key or session header. On our practice API, the token only works together with the X-Sandbox-Key header returned by login. Fix: read the API docs and the login response headers. Add the missing header on the collection so every request gets it.

5. "Bearer" was typed twice

Symptom: the Console shows Authorization: Bearer Bearer eyJ.... Why: with Auth Type Bearer Token, Postman adds the word Bearer for you (see Postman's authorization types). If you paste Bearer abc, it is sent twice. Fix: paste only the token. If you prefer to write the header by hand in the Headers tab, set Auth Type to No Auth so the two do not fight.

6. Quotes, spaces or line breaks around the token

Symptom: the token in the Console starts with " or has a trailing space. Why: the token was copied from a JSON response with its quotes, or a script saved the whole JSON string. Fix: store the bare value. In a script, use pm.response.json().token, not JSON.stringify(...).

7. Wrong auth type

Symptom: the header starts with Basic but the API expects Bearer, or the reverse. In our run, correct username and password sent as Basic Auth still failed, because that API only accepts Bearer tokens. Fix: match the auth type in the API docs. For OAuth 2.0, use Postman's OAuth 2.0 type to fetch the token, then confirm it is added to the request header.

8. The token expired or belongs to another environment

Symptom: it worked earlier, now it fails with the same setup. Why: many tokens last minutes, not days. Our practice API's tokens last 900 seconds (15 minutes), as its login response states with "expiresInSec":900. A staging token will not work on production either. Fix: log in again, and automate the token refresh (next section) so it never goes stale by hand.

Quick diagnosis table

Find what you see in the Console, then jump to the fix.

What the Console showsMost likely causeFix
No Authorization header at allNo Auth, or parent has No AuthSet Bearer Token on the collection
Bearer {{token}} as textVariable unset or wrong environmentSelect environment, run login first
Bearer Bearer ...Prefix typed in the token fieldPaste only the token
Bearer "eyJ..."Quotes saved with the tokenSave the bare value in your script
Basic dXNlcj...Wrong auth typeSwitch to the type the API documents
Header looks right, still 401Expired token, wrong environment, or a missing extra headerLog in again; check docs for API key or tenant headers
401 on the login requestWrong credentials or body formatCheck case, body type and Content-Type
Works in Postman, 401 in Newman or CIEnvironment file not passed, or secret empty in CIRun with -e env.json and check CI secrets

Stop 401s coming back: save the token automatically

Most repeat 401s come from copying tokens by hand. Let the login request save the token for every other request.

  1. On the collection, set Auth Type to Bearer Token and the Token field to {{token}}.
  2. Leave every request on Inherit auth from parent. Set the login request itself to No Auth.
  3. In the login request, add this to the Scripts > Post-response tab (called Tests in older versions):
// Runs after the login response arrives
pm.test("login succeeded", () => pm.response.to.have.status(200));

const body = pm.response.json();
pm.collectionVariables.set("token", body.token);

// Only needed if your API returns an extra session header, like our practice API
const sandbox = pm.response.headers.get("X-Sandbox-Key");
if (sandbox) pm.collectionVariables.set("sandbox", sandbox);

We ran this exact script in the Newman test above; it saved both values and the next request returned 201 Created. Change body.token to match your API's field name (for example access_token). Keep real tokens in environment or vault values, not in a shared collection, so they are not exported by mistake.

Want to go further with scripts and checks? Our guide to validating JSON responses in Postman shows how to assert on the body once auth works.

Turn the 401 into test cases

Once you understand why 401 happens, test it on purpose. For each protected endpoint, add these requests to your collection:

  1. No Authorization header → expect 401.
  2. Random token → expect 401.
  3. Token with Bearer missing → expect 401, not 500.
  4. Expired token (ask developers for a short-lived one) → expect 401.
  5. Valid token → expect 2xx.
  6. Valid token, lower-role user → expect 403, not 401.

A simple check for the negative cases:

pm.test("rejects missing token with 401", () => {
  pm.response.to.have.status(401);
  pm.expect(pm.response.text()).to.not.include("stack");
});

Not sure whether a case should be 401 or 403? Read 401 vs 403 explained with real responses. For token-specific checks such as expiry and signature tampering, see testing JWT authentication in Postman and other tools.

Interview answer: "You get 401 in Postman. What do you do?"

Say this: "401 means the server did not accept my credentials for that request. First I open the Postman Console and check the Authorization header that was actually sent. Usually it is missing, has an unresolved variable, has Bearer typed twice, or the token has expired. If the login call itself gives 401, the credentials or body format are wrong. Once fixed, I save the token from the login response into a collection variable with a post-response script, so every request inherits it and the problem doesn't come back."

Likely follow-ups: "How is 401 different from 403?" (401 is not authenticated; 403 is authenticated but not allowed). "It works in Postman but fails in Newman. Why?" (environment file not passed, or a CI secret is empty). More practice questions are in our Postman interview questions list.

Practice exercise

Try this on the free practice API from the API Playground (base URL shown on that page).

  1. Create a collection with Bearer Token auth set to {{token}}.
  2. Send POST /products with {"name":"Test","price":5} before logging in. Note the status and error code.
  3. Add a login request (POST /auth/login, body {"username":"qa.tester","password":"Practice@123"}) with the script above.
  4. Run login, then the product request again, but leave out X-Sandbox-Key.
  5. Add the header X-Sandbox-Key: {{sandbox}} to the collection and run once more.
Answer

Step 2 returns 401 with token_invalid (the variable is unset, so the literal text {{token}} is sent). Step 4 returns 401 token_invalid (extra header missing). Step 5 returns 201 Created with the new product and an id. If you instead set the request to No Auth in step 2, you would see token_missing.

Next step

If you are new to Postman, work through the free Postman API testing tutorial next; it covers collections, environments and scripts from the start. To run your fixed collection in CI, follow the Newman CLI and CI/CD guide. For structured learning with certificates, browse the free QA courses.

Stuck on a 401 that none of these explain? Post the sent headers (with the token removed) in the QA Community and other testers can help you spot it.

Key takeaways

  1. 1Always check the request that was actually sent (Postman Console), not what the Authorization tab looks like.
  2. 2An unset variable such as {{token}} is sent as literal text and gives 401.
  3. 3In the Bearer Token type, paste only the token. Postman adds the word Bearer itself.
  4. 4A 401 from the login request itself means wrong username or password, not a token problem.
  5. 5Save the token from the login response with a script so it never goes stale by hand.
  6. 6Some APIs need an extra header (API key, tenant or session key) next to the token.

Common mistakes to avoid

  • Typing "Bearer " inside the Bearer Token field, so the header becomes Bearer Bearer <token>.
  • Running a request with the wrong environment selected, so {{token}} has no value.
  • Setting the request to Inherit auth from parent when the folder or collection has No Auth.
  • Copying a token from an old run after it has expired.
  • Using Basic Auth on an API that only accepts Bearer tokens.
  • Reading 401 as a server bug before checking the request in the Console.

References

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6