Script in a logged-in browser
- What WordPress expects
- Cookie plus a nonce for the
wp_restaction - Result when missing
- User is set to 0, so the call is unauthenticated even though you are logged in
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.
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.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
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.wp_rest actionThe 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:
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.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}}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: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' }),
});curl --user "USERNAME:PASSWORD" https://HOSTNAME/wp-json/wp/v2/users?context=edit// 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:
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.
2 questions people ask next, answered from the sources on this page.
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.
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.
Run the free audit, then approve the fixes. Every change can be undone.