HTTP error reference
401 Unauthorized
A 401 Unauthorized means the server needs you to prove who you are, and the request either had no credentials or ones it did not accept. Despite the name, it is about authentication: logging in, or sending a valid token, should fix it.
If you are visiting the site
Log in again, or clear the site’s cookies if your session may have expired. If the browser shows a username and password box, the site or a staging area is password-protected.
Common causes
Missing or expired credentials
A session cookie expired, an API token was revoked, or the request was sent without one.
Wrong credentials
A mistyped password, a key for the wrong environment, or a token with the wrong format, such as a missing “Bearer ” prefix.
The Authorization header never arrives
Behind Apache with PHP running as CGI or FastCGI, the Authorization header is hidden from scripts by default. Requests from the WordPress REST API with application passwords then fail with 401 even when the password is right.
Server-level password protection
Basic authentication on a staging site, set with .htpasswd or Nginx auth_basic, sits in front of the application.
How to fix it
Apache
- Add CGIPassAuth On (Apache 2.4.13 and later) to the site configuration or .htaccess so scripts receive the Authorization header.
APIs
- Check the exact header the API expects, for example Authorization: Bearer <token>, and that the token belongs to the right account and environment.
- Keep tokens and passwords out of logs and screenshots you share while debugging.
Nginx
- If auth_basic protects a folder, check the password file path and that the user exists in it.
Quick checklist
Check the authentication challenge and session expiry.
Verify the expected authentication scheme.
Keep tokens and passwords out of shared diagnostic logs.
Questions about 401 errors
What is the difference between 401 and 403?
A 401 means “I do not know who you are”: send valid credentials and you may get in. A 403 means “I know, and the answer is no”.
Why does the WordPress REST API return 401 with the right password?
Usually the Authorization header is being stripped before it reaches PHP. On Apache, CGIPassAuth On fixes it.