Free auditStart free
GuideError · HTTP status codes

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.

3 min
read
5
sources
Oct 29, 2026
updated
Scaplet Editorial Team
author
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
  2. Reproduce and check it in 2 minutes
  3. Fix by client type
  4. 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 withChatGPTClaudePerplexityGoogleAI Mode
02Check 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}}
03Fix 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. Without it WordPress sets the current user to 0:
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
curl --user "USERNAME:PASSWORD" https://HOSTNAME/wp-json/wp/v2/users?context=edit
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
04Explained

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.

Questions

Asked a lot.

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

01Why 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.

02Why 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. 01WordPress REST API handbook: Authenticationdeveloper.wordpress.org · checked 2026-11-01
  2. 02WordPress Core: Application Passwords integration guidemake.wordpress.org · checked 2026-11-01
  3. 03WordPress developer reference: rest_authorization_required_code()developer.wordpress.org · checked 2026-11-01
  4. 04WordPress developer reference: wp_is_application_passwords_available()developer.wordpress.org · checked 2026-11-01
  5. 05How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Free · 2 minutes

Tools point. Agencies advise. This one ships.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane