Error guide / The REST API encountered an error
How to fix "The REST API encountered an error" in WordPress
The notice means WordPress did not get a normal JSON answer from its own REST API. The block editor saves posts through this API, and Tools > Site Health tests it by having the server request its own address /wp-json/wp/v2/types/post?context=edit as a logged-in administrator. That request came back as a 403, a 404, a 500, a timeout, or a response with extra output mixed into the JSON. Administrators see the notice in Site Health, and editors usually meet the same problem as "Updating failed. The response is not a valid JSON response." in the editor. You do not have to start by deactivating plugins one by one: what your site returns to an outside request already narrows the cause to one of four situations, and the check on this page shows that response in a few seconds.
Check your site
What causes it
Most often something blocks the request before it reaches WordPress: a security plugin with a "disable REST API" option, a firewall rule at the host (on shared hosting usually ModSecurity), or Cloudflare's WAF and bot protection. The next most common cause is broken rewrite rules: the site itself works, but /wp-json/ returns 404. This typically follows a migration, an .htaccess edit, or an nginx config without the right try_files. A PHP fatal error or memory exhaustion in a plugin that hooks into rest_api_init produces a 500. The rarest case is the hardest to pin down: the API answers normally from outside, and only the server's request to itself fails. Local DNS, an outbound firewall, HTTP auth on a staging site, or a host that refuses connections from its own IP can each cause it.
How to fix it
- Run the check on this page against https://yoursite.com/wp-json/wp/v2/ and read the status code. 200 means the API answers outside requests, 403 means something blocks it, 404 means the route or the rewrite rules are gone, and 500 means PHP fails inside WordPress. Look at the final URL and the Server header as well: an unexpected redirect, or cloudflare as the Server value, shows what else sits in the request path.
- Before you change anything the check points to, make a full backup of the files and the database. The likely fixes touch .htaccess, plugin settings and firewall rules on a live site, and you need a way back.
- A 403 means the request never reached WordPress. Turn off any "disable REST API" or REST hardening option in your security plugin (Wordfence, Solid Security and similar plugins all have one). Ask your host to check the ModSecurity log for your IP at the minute you ran the check. In Cloudflare, open Security > Events, find the rule that matched /wp-json/ and add a skip rule for that path.
- For a 404, open the URL in a browser. A JSON body with rest_no_route means WordPress answered and a plugin or code snippet removed the routes. An HTML 404 page means the rewrite rules are broken: go to Settings > Permalinks and press Save without changing anything, which rebuilds them. If https://yoursite.com/?rest_route=/wp/v2/ returns JSON while /wp-json/ still gives 404, the missing piece is the WordPress rewrite block in .htaccess or the try_files line in your nginx config.
- A 401 with a JSON body such as {"code":"rest_not_logged_in"} means the API works and asks for a login, which is normal on routes that require one. Look for a membership, maintenance or password-protection layer that extends the login requirement to every route. A 500 is a real failure inside PHP: find the fatal error or the memory exhaustion line in your host's PHP error log, then fix or deactivate the plugin it names.
- If the check returns 200, open the same URL in a browser and look at what comes before the opening brace. A PHP warning, stray HTML or a blank line from a BOM in wp-config.php or a plugin file produces the "did not behave correctly" variant of the notice, and that file has to be cleaned. If the JSON is clean, the public API works and only the server's loopback request fails. Send your host the exact Site Health text, which names the cURL error (for example "cURL error 28: Operation timed out"), and ask them to confirm that the server can reach its own domain over HTTPS.