Skip to content

WordPress REST API errors: debugging the rest_no_route, rest_forbidden, and 500s

WordPress REST API errors come in a small number of recognizable patterns. Here is how to debug each WordPress REST failure — from rest_no_route to authentication mismatches.

The WordPress REST API is what Gutenberg, the mobile app, and every modern headless setup depend on. When it breaks, the symptoms are loud: Gutenberg shows “Updating failed”, mobile apps spin, headless front-ends 502. The error messages from /wp-json/ are precise — rest_no_route, rest_forbidden, rest_cookie_invalid_nonce — and each one points at a specific layer.

What’s happening

REST API requests hit /wp-json/{namespace}/{route}. WordPress’s rewrite rules translate that into a call to the registered endpoint’s callback. Authentication runs first (cookies for browsers, app passwords or JWT for clients), then the route’s permission_callback runs, then the route’s callback. A failure at any of those layers returns a structured JSON error with a code, message, and data.status.

Common error codes: rest_no_route (404 — no endpoint matched, often because permalinks need flushing), rest_forbidden (401/403 — auth or capability fail), rest_cookie_invalid_nonce (403 — the nonce expired), rest_disabled (a security plugin turned REST off), and plain 500s from a fatal in the endpoint callback.

How to verify

curl -i https://example.com/wp-json/wp/v2/posts
curl -i https://example.com/wp-json/  # lists all namespaces
curl -i -b cookies.txt https://example.com/wp-json/wp/v2/users/me \
  -H "X-WP-Nonce: $(wp eval 'echo wp_create_nonce("wp_rest");')"
wp eval 'var_dump(rest_get_server()->get_routes());' | head -40
wp rewrite list | grep wp-json

For a quick auth check from outside WP-CLI:

curl -u "user:application-password" \
  https://example.com/wp-json/wp/v2/posts \
  -X POST -H "Content-Type: application/json" \
  -d '{"title":"test","status":"draft"}'

The fix

  1. For rest_no_route, flush rewrites. wp rewrite flush. After registering custom endpoints, this is mandatory. Without it, the rewrite table doesn’t know about /wp-json/{your-namespace}/{your-route}.
  2. For 404s on the entire /wp-json/, check the web server config. Nginx needs the try_files block to pass /wp-json/* to index.php. Apache needs .htaccess intact. If curl /wp-json/ returns a 404 but the homepage works, this is your layer.
  3. For rest_cookie_invalid_nonce, refresh. The browser nonce for REST is wp_rest. Use wpApiSettings.nonce in JS, generated fresh on each pageload. For long-lived UIs, refresh via heartbeat.
  4. For rest_forbidden, check the permission_callback. The endpoint’s permission_callback returns false for the current user. Use Query Monitor’s REST API panel to see which capability was checked.
  5. For 500s, read debug.log. A PHP fatal in a REST callback returns 500 with a generic JSON error. The full trace is only in the log file. Reproduce with WP_DEBUG_LOG = true and read debug.log.
  6. Check for REST blockers. Some “disable REST” plugins or add_filter('rest_authentication_errors', ...) snippets in functions.php block REST entirely. Search the codebase for rest_authentication_errors and rest_enabled.

For headless and Gutenberg-driven sites where REST reliability is load-bearing, Stack Harbor monitors the REST surface as part of enterprise WordPress hosting. To diagnose a REST failure, book a consult.