WordPress REST API 401 Unauthorized: 4 Causes and Fixes

A WordPress REST API 401 Unauthorized error with a valid application password can come from several layers: the Authorization header, HTTPS, the username, or a security plugin or host firewall. Test them in that order with curl, change one thing per test, and the failing layer shows itself.

Tested on: I did not run these commands against a live host for this article. They follow the official docs linked below, and I flag the one claim I could not verify.

Key takeaways

  • A 401 with restnotlogged_in on /wp-json/wp/v2/users/me, despite correct credentials, points to a stripped Authorization header.
  • An empty authentication key at /wp-json/ means application passwords are unavailable: no HTTPS, or the feature is disabled.
  • Wrap the 24-character application password in single quotes. Spaces inside it are harmless to WordPress.
  • Compare response headers with and without credentials to tell a WAF block from a WordPress 401.

Fix a WordPress REST API 401 Unauthorized error one layer at a time

The error code in the response body tells you which layer answered. Send one authenticated request, read the code, and fix only that layer. Don’t test from a logged-in browser tab: per the REST API Handbook (opens in a new tab), cookie authentication without a nonce sets the current user to 0, so the request counts as unauthenticated.

Bash
curl -i -u 'jane_admin:abcd EFGH 1234 ijkl MNOP 6789' https://example.com/wp-json/wp/v2/users/me
ResponseLayer to fix
200 with your user as JSONAuthentication works. Look at your client code.
401 restnotlogged_inWordPress saw no credentials. The header was stripped or removed upstream.
A 401 with a different error code from WordPressWordPress may have received the credentials and rejected them. Check username and password.
HTML page, or a 401/403 not from WordPressA WAF or proxy answered first.

The usual server-side cause of the second row is Apache running PHP under CGI or FastCGI, which can drop the Authorization header before WordPress reads it. Add this above the # BEGIN WordPress block in .htaccess, then send the request again:

Apache
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

I believe this rule only helps on Apache. I could not verify that against the docs. Nginx never reads .htaccess, so on nginx the host must pass the header to PHP in its own config. The directive usually used for that is fastcgiparam HTTPAUTHORIZATION $http_authorization; inside the PHP location block. I did not test it here, so check it against your host’s documentation and run nginx -t before you reload.

On shared hosting you often can’t edit the server config. Open a ticket and ask one exact question: does the host pass the Authorization header through to PHP?

Read the status code first: 401 versus 403

A 401 means WordPress treated the request as logged out. A 403 usually means WordPress knew who you were and refused the action, for example an Editor trying to manage users.

That gives you a simple decision rule. If the response is a 403 and your credentials are correct, stop debugging the header. Check the user’s role instead, or repeat the request as an administrator to confirm. If the response is a 401, keep working down the layers below.

Application passwords need HTTPS, so check the REST root first

Check the REST root first: it tells you whether application passwords are available. Per the integration guide (opens in a new tab), an empty authentication key means application passwords are unavailable, perhaps because the request isn’t over https:// or the feature was intentionally disabled. Run this before anything else.

Bash
curl -s https://example.com/wp-json/ | jq '.authentication'

An application-passwords object in the output means the feature is on, and you can move to the next layer. An empty result means you should check that the URL you call is https:// and that no plugin or filter disables application passwords. The filter to search your code for is wpisapplicationpasswordsavailable. When a CDN or reverse proxy sits in front of your site, test the origin server as well as the public URL.

This matters for every client, not only scripts. Outside apps such as the C# examples for custom post types (opens in a new tab) [1] and database access (opens in a new tab) [2] in Chakraborty and Aithal’s 2024 papers reach WordPress through the same REST API, so they hit the same HTTPS requirement.

Use the login name, and ignore the advice about spaces

Use the login name, not the display name. The handbook’s curl example says USERNAME, and the integration guide’s successurl returns userlogin, so the login name is the documented identifier. You’ll find yours under Users, All Users, in the Username column.

Bash
curl -i -u 'jane_admin:abcd EFGH 1234 ijkl MNOP 6789' https://example.com/wp-json/wp/v2/users/me
curl -i -u 'jane@example.com:abcd EFGH 1234 ijkl MNOP 6789' https://example.com/wp-json/wp/v2/users/me

The second command returns a 401 and the first returns 200? Then you have your answer. Clients that create or edit posts and other content over REST, like the C# code in this post CRUD study (opens in a new tab) [3], send the same Basic Auth pair, so a wrong username fails the same way in any language.

If both commands fail, rule out the password itself. Open Users, Profile, scroll to Application Passwords, and create a fresh one. A revoked entry or a copy error fails the same way as a wrong username, and a new password takes ten seconds to test.

Spaces in the password are often blamed, but the integration guide says they are not a cause. Application passwords are 24 characters, generated without special characters, and displayed in chunks like abcd EFGH 1234 ijkl MNOP 6789. They work with or without the spaces, because spaces are stripped before the password is hashed and verified. The real trap is the shell: without single quotes, curl receives the password split across arguments.

Rule out a security plugin or host WAF before you install anything

A security layer is the cause when the 401 or 403 does not come from WordPress. Send an unauthenticated request, then an authenticated one, and compare the headers.

Bash
curl -I https://example.com/wp-json/
curl -I -u 'jane_admin:abcd EFGH 1234 ijkl MNOP 6789' https://example.com/wp-json/wp/v2/users/me

Look for differences in the Server header or the body. A different Server header on the authenticated response, a challenge page, an HTML body, or a missing Link header all mean a firewall answered first. Running a plugin such as Wordfence? Check its firewall log for the blocked request.

A tempting shortcut for a 401 is installing a Basic Auth plugin or switching off security plugins to see what happens. The handbook says its Basic Authentication plugin sends your username and password with every request and belongs in development and testing only. Application passwords are the preferred route.

If you must test with a security plugin off, do it on a staging copy, change one setting, and send the same curl request again. Two changes at once tell you nothing.

Note: WordPress 7.2 Beta 5 lists email notifications when application passwords are created. It is a beta for testing only, with final release scheduled for December 8, 2026. Don’t install it on a production site to debug a 401.

Escalate to your host when the header rule changed nothing and the failing response is not from WordPress. Send them the curl -I output from both requests.

Next step: open the authorization flow section of the integration guide and run the /wp-json/ check from your own server, so you know the feature is on before you debug anything else.

Frequently Asked Questions

Why does the WordPress REST API return 401 Unauthorized with a valid application password?

WordPress is not receiving or accepting the credentials. The usual causes are a stripped Authorization header, a request not served over HTTPS, a wrong username, or a firewall that answers before WordPress does. Test them in that order with curl and change one thing per test.

How do I use WordPress REST API authentication with application passwords?

Create a password under Users, Profile, Application Passwords, then send it with your login name as Basic Auth, for example curl -u 'login:password' https://example.com/wp-json/wp/v2/users/me. Check that /wp-json/ lists an application-passwords object under authentication first. If that key is empty, the feature is unavailable on that request.

What does the restnotlogged_in error mean?

WordPress treated the request as unauthenticated. With correct credentials, that points to an Authorization header removed before PHP read it, often on Apache running PHP under CGI or FastCGI. Add the .htaccess rewrite rule shown above, or ask your host to pass the header through.

Do spaces in a WordPress application password cause a 401?

No. The integration guide says the password works with or without the spaces, because they are stripped before verification. If it fails in curl, the cause is usually missing single quotes around the user:password pair.

How can I tell if a firewall or WordPress sent the 401?

Send one unauthenticated and one authenticated curl -I request and compare the headers. A different Server header, an HTML or challenge-page body, or a missing Link header means a WAF or proxy answered first. A JSON body with a WordPress error code means WordPress answered.

References

  1. "CRUD Operation On WordPress Custom Post Type (CPT) From C# Over REST API", Chakraborty and Aithal, 2024. doi:10.2139/ssrn.4684560 (opens in a new tab)
  2. "CRUD Operation on WordPress Database Using C# And REST API", Chakraborty and Aithal, 2024. doi:10.2139/ssrn.4729159 (opens in a new tab)
  3. "CRUD Operation on WordPress Posts From C# Over REST API", Chakraborty and Aithal, 2024. doi:10.2139/ssrn.4770800 (opens in a new tab)