Rest API 401 error - but I use the correct credentials

50 Views Asked by At

I get this error when trying to get a list of users:

Error making API request: 401 Client Error: Unauthorized for url: https://www.website.com/wp-json/wp/v2/users?context=edit

And yes, the credentials are correctly inserted. The user has admin status, and i have tried to create 5 different application passwords...

I have tried to solve this by doing everything: creating a new htaccess file (it currently consists of:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

). I have also tried to deactivate WordFence, and every other plugin, but nothing helps...

This is really weird, because i have 4 other sites, with identical tech setup (same plugins installed etc), and for those, I can easily authenticate. Something must be wrong here..

Application passwords, Create admin user, htaccess, deactivate plugins.

1

There are 1 best solutions below

0
Kasper Toft Braun On

@Tommizzy gave the correct answer in a comment: Make sure your WordPress user's user name does not have a space.

My user name was "test user", and once I changed it to "testUser", I am now able to authenticate using the API.