# 401 Unauthorized in the WordPress REST API

> Why wp-json returns 401 rest_cannot_create: missing nonce, no application password, HTTP instead of HTTPS. Fix each with working curl and PHP snippets.

Canonical: https://scaplet.com/errors/http/401/wordpress

Guide Error · HTTP status codes

Why wp-json returns 401 rest_cannot_create: missing nonce, no application password, HTTP instead of HTTPS. Fix each with working curl and PHP snippets.

3 min

read

5

sources

Oct 29, 2026

updated

Scaplet Editorial Team

author

401 4xx · Client error

The short answer

A WordPress REST API 401 means the request reached WordPress as no user. Logged-out requests get 401, logged-in ones get 403, per rest_authorization_required_code(). Browser code needs an X-WP-Nonce header; remote clients need an application password sent as Basic auth over HTTPS.

1. [Who WordPress thinks you are](#who-wordpress-thinks-you-are)
2. [Reproduce and check it in 2 minutes](#reproduce-and-check-it-in-2-minutes)
3. [Fix by client type](#fix-by-client-type)
4. [What it means for SEO and crawlers](#what-it-means-for-seo-and-crawlers)

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F401%2Fwordpress%20(%22401%20Unauthorized%20in%20the%20WordPress%20REST%20API%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F401%2Fwordpress%20(%22401%20Unauthorized%20in%20the%20WordPress%20REST%20API%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F401%2Fwordpress%20(%22401%20Unauthorized%20in%20the%20WordPress%20REST%20API%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F401%2Fwordpress%20(%22401%20Unauthorized%20in%20the%20WordPress%20REST%20API%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_The three ways a request becomes 'no user'

## Who WordPress thinks you are

The REST API runs a capability check for each route. If the check fails, WordPress picks the status with `rest_authorization_required_code()`, which per the developer reference returns 401 when the user is not logged in and 403 when they are. So a 401 tells you the request carried no recognized identity, and a 403 would mean it did but lacked the capability. Compare with [WordPress 403](/errors/http/403/wordpress).

Client

### Script in a logged-in browser

What WordPress expects

Cookie plus a nonce for the `wp_rest` action

Result when missing

User is set to 0, so the call is unauthenticated even though you are logged in

Client

### Remote app or curl

What WordPress expects

Application password as Basic auth over [HTTPS](/glossary/https)

Result when missing

401 with no user

Client

### Anything else

What WordPress expects

A plugin: OAuth 1.0a Server, JSON Web [Tokens](/glossary/tokenization)

Result when missing

Depends on the plugin

_02_Check it

## Reproduce and check it in 2 minutes

This public site is a real WordPress install. An anonymous attempt to create a post returned a 401 and the exact error code when I ran it:

The same call against your own site should differ only in the host. If it already returns 401 for a read-only call such as `/wp-json/wp/v2/posts`, an authentication plugin or firewall rule is demanding credentials for everything. Then test credentials, replacing the host, user and application password:

Your own site: same call with an application password

```
curl --user "USERNAME:APP-PASSWORD" -X POST https://example.test/wp-json/wp/v2/posts -d 'title=test' -d 'status=draft' # Expect: 201 Created with the new draft. 401 again means the credentials did not authenticate.
```

Public WordPress site: anonymous create-post request

```
curl -s -X POST https://developer.wordpress.org/wp-json/wp/v2/posts -d 'title=x' # Observed: {"code":"rest_cannot_create","message":"Sorry, you are not allowed to create posts as this user.","data":{"status":401}}
```

_03_Fix it on your stack

## Fix by client type

Browser code first. Cookie authentication needs a nonce created for the `wp_rest` action. The REST docs say to send it as the `X-WP-Nonce` header, which is the most reliable choice and especially for DELETE, or as `_wpnonce` in the request data or [query string](/glossary/url-parameters). Without it WordPress sets the current user to 0:

Cookie auth: send the nonce in a header
Cookie auth: send the nonce in a header

```
fetch('/wp-json/wp/v2/posts', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': nonce, // created for the wp_rest action }, body: JSON.stringify({ title: 'Test', status: 'draft' }), });
```

Application password with curl, from the integration guide
Application password with curl, from the integration guide

```
curl --user "USERNAME:PASSWORD" https://HOSTNAME/wp-json/wp/v2/users?context=edit
```

Availability filter (only force it on knowing the risk)
Availability filter (only force it on knowing the risk)

```
// Disable for the whole site add_filter( 'wp_is_application_passwords_available', '__return_false' ); // Force on, including over plain HTTP: not recommended add_filter( 'wp_is_application_passwords_available', '__return_true' );
```

Remote clients should use application passwords, available since WordPress 5.6. You generate one on the Edit User page. The REST authentication handbook describes passing them as Basic auth on requests served over https://. The integration guide shows this curl call:

If the user's profile page shows no application password section at all, availability is the issue. The reference says application passwords are by default available to sites using SSL or to local environments. The `wp_is_application_passwords_available` filter can turn them off or on, and the guide's warning is that without SSL a network attacker could see the password:

Use application passwords when
- A server, script or CI job calls the API
- The site is served over HTTPS
- You can revoke one credential per integration

Use cookie plus nonce when
- The code runs in the logged-in admin or a theme page
- The user is already logged in through wp-admin
- You want no stored secret at all

**Do not use the Basic Authentication plugin in production**The REST handbook says the Basic Authentication plugin sends credentials with every request and should only be used for development and testing; application passwords are preferred.

_04_Explained

## What it means for SEO and crawlers

The REST API is not where pages are crawled, but themes and plugins sometimes render content from it. Google's documentation says it does not index URLs returning 4xx and that you should not use 401 or 403 to limit crawling. If a page's visible content comes from a REST call that returns 401 to anonymous visitors, crawlers see the same failure. Make public data readable without authentication, and keep write routes private. For missing pages see [404 in WordPress](/errors/http/404/wordpress).

Questions

## Asked a lot.

2 questions people ask next, answered from the sources on this page.

_01_ Why do I get 401 while logged in to wp-admin?

Cookie authentication also requires a nonce for the wp_rest action. Without it WordPress sets the current user to 0, so the request is unauthenticated even though your browser has the login cookies.

_02_ Why is there no application password section on my profile?

By default they are available to sites using SSL or local environments. A plugin or the wp_is_application_passwords_available filter may also have turned them off.

Sources · 5

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- wordpress.org
- google.com

1. 01 [WordPress REST API handbook: Authentication](https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/) developer.wordpress.org · checked 2026-11-01
2. 02 [WordPress Core: Application Passwords integration guide](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/) make.wordpress.org · checked 2026-11-01
3. 03 [WordPress developer reference: rest_authorization_required_code()](https://developer.wordpress.org/reference/functions/rest_authorization_required_code/) developer.wordpress.org · checked 2026-11-01
4. 04 [WordPress developer reference: wp_is_application_passwords_available()](https://developer.wordpress.org/reference/functions/wp_is_application_passwords_available/) developer.wordpress.org · checked 2026-11-01
5. 05 [How HTTP status codes affect Google's crawlers](https://developers.google.com/search/docs/crawling-indexing/http-network-errors) developers.google.com · checked 2026-11-01

## Keep learning

[All errors](/errors)

[Learn HTTP 401 Unauthorized HTTP status codes](/errors/http/401) [Related 4xx errors Status codes and links](/seo-issues/4xx-errors) [Read next 403 Forbidden in WordPress HTTP status codes](/errors/http/403/wordpress) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 401 errors
[401 Unauthorized in IIS](/errors/http/401/iis) [401 Unauthorized in Laravel](/errors/http/401/laravel) [401 Unauthorized in Spring Boot](/errors/http/401/spring-boot) [HTTP 401 Unauthorized](/errors/http/401)

Nearby in errors
[402 Payment Required](/errors/http/402) [403 Forbidden](/errors/http/403)

More in HTTP 401 Unauthorized
[401 Unauthorized in IIS](/errors/http/401/iis) [401 Unauthorized in Laravel](/errors/http/401/laravel) [401 Unauthorized in Spring Boot](/errors/http/401/spring-boot) [401 Unauthorized in the WordPress REST API](/errors/http/401/wordpress)

Terms on this page
[HTTPS](/glossary/https) [Tokenization](/glossary/tokenization) [URL parameters](/glossary/url-parameters)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
