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
- 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}. - For 404s on the entire
/wp-json/, check the web server config. Nginx needs thetry_filesblock to pass/wp-json/*toindex.php. Apache needs.htaccessintact. Ifcurl /wp-json/returns a 404 but the homepage works, this is your layer. - For
rest_cookie_invalid_nonce, refresh. The browser nonce for REST iswp_rest. UsewpApiSettings.noncein JS, generated fresh on each pageload. For long-lived UIs, refresh via heartbeat. - For
rest_forbidden, check the permission_callback. The endpoint’spermission_callbackreturns false for the current user. Use Query Monitor’s REST API panel to see which capability was checked. - 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 withWP_DEBUG_LOG = trueand readdebug.log. - Check for REST blockers. Some “disable REST” plugins or
add_filter('rest_authentication_errors', ...)snippets infunctions.phpblock REST entirely. Search the codebase forrest_authentication_errorsandrest_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.