Troubleshooting · Troubleshooting
How to Fix the REST API Error in Site Health in WordPress
Short answer
Open Tools → Site Health and expand the REST API item to read the exact error and response code. In most cases the fix is to save your permalinks, deactivate plugins one at a time to find a conflict, or allow /wp-json/ through your firewall. If the error stays after those steps, turn on debug logging to find the PHP error, then ask your host to check the server.
Key takeaways
- Site Health tests the REST API by requesting wp/v2/types/post with context=edit and expects a 200 response within 10 seconds.
- A failed request is marked critical, while a non-200 response is marked as an unexpected result in Site Health.
- The block editor relies on the REST API to display and save posts, so this error can stop saving.
- Save permalinks, check plugins one at a time, and check firewall rules before you ask your host for help.
- Debug logging writes PHP errors to wp-content/debug.log, which often names the plugin or code behind the error.
- A firewall rule that blocks /wp-json/ should be narrowed to allow that path, not switched off for the whole site.
What does “The REST API encountered an error” mean in Site Health?
The message means WordPress asked its own REST API for data and the request failed, so Site Health marks the test as critical.
The REST API is one way WordPress and other applications communicate with the server, and the block editor screen relies on it to display and save posts and pages. WordPress Developer Resources states this in the code for the REST API availability test.
The test requests the wp/v2/types/post endpoint with context=edit, sends your login cookie and a nonce, and waits up to 10 seconds for a reply. A reply of 200 means the test passes.
If the request returns a WordPress error, Site Health shows the label “The REST API encountered an error” with a critical status. If the request returns a different status code, such as 403, the label changes to “The REST API encountered an unexpected result” with a recommended status.
Why does this error stop the block editor from saving?
The block editor saves posts through the REST API, so when the API fails, the editor cannot display or save your posts and pages.
The REST API Handbook calls the API the foundation of the WordPress block editor. It sends and receives data as JSON objects, and the editor uses those JSON responses to load and store content.
When the API returns an error page, a redirect, or extra text instead of JSON, saving fails. Kinsta describes the result as “Updating failed” or “Publishing failed” errors in the editor, and notes that the Site Health tool shows the exact error behind them.
Other tools that use the API can fail too, such as some contact forms and plugins that save settings through API requests. The front of your site can still load while the editor is broken, which is why the error is easy to miss.
How do you read the exact error message in Site Health?
Open Tools → Site Health, expand the REST API item, and copy the endpoint and response lines shown under it.
The Status tab groups results into critical issues, recommended improvements, and passed tests, according to the Site Health screen documentation. Expand the REST API item to see the full text.
The detail shows the REST API endpoint that was tested and the response, such as a status code or an error message. Kinsta notes the response can be a 401, an operation timeout, a 403, or a “Cookie Nonce Is Invalid” message.
Note the exact wording before you change anything, since the code points to the cause. The Info tab also has a button to copy all site info to the clipboard, which is useful when you ask your host for help.
What are the most common causes of the REST API error?
A firewall rule, a plugin conflict, broken permalinks, a PHP error, or a server problem is the usual cause, and the response code points to which one.
| Cause | What you see | First check |
|---|---|---|
| Firewall or security plugin | 403 Forbidden | Check the security plugin settings and firewall logs for a blocked request to /wp-json/ |
| Plugin or theme conflict | 500 error or blank response | Deactivate plugins one at a time and re-check Site Health; see how to fix a 500 error |
| Broken permalinks | 404 on /wp-json/ | Go to Settings → Permalinks and save changes |
| PHP error in a plugin | Invalid JSON response | Turn on debug logging and read wp-content/debug.log |
| Server timeout | Request times out after 10 seconds | See the cURL error 28 fix and ask your host to check loopback requests |
| Password-protected staging | 401 Unauthorized | Remove the password or allow the server's own requests through |
An active PHP session can also break the test. The Site Health documentation says a PHP session interferes with REST API and loopback requests, and the session should be closed with session_write_close() before HTTP requests are made.
The timeout case is closely tied to loopback requests, which WordPress uses to run scheduled events and check theme and plugin edits. Our guide to fixing a failed loopback request covers that check in detail.
Site Health also flags an outdated PHP version as a critical issue. If your PHP version is old, follow our guide on how to update PHP for WordPress once the API error is fixed.
How do you test the REST API endpoint yourself?
Open your site address followed by /wp-json/ in a browser, and a working site returns a JSON page that names the site and lists its namespaces.
A JSON reply means the API answers. A 404 means the request never reached WordPress routing, which points to permalinks or rewrite rules. A 403 page means something blocked the request before WordPress answered it.
A blank page or a 500 error points to a PHP fatal error, often from a plugin. Check the same address after you deactivate plugins to see if the reply changes.
You can also open /wp-json/wp/v2/types/post directly, which is the route Site Health tests. A reply that starts with JSON and includes post type data means that route works.
How do you find a plugin or theme that breaks the REST API?
Deactivate all plugins, re-check Site Health, then reactivate them one at a time until the error returns.
- Note which plugins are active, so you can restore the same set later.
- Go to Plugins → Installed Plugins, select all plugins, choose Deactivate from the bulk actions menu, and click Apply.
- Reload Tools → Site Health and check the REST API item.
- If the error is gone, reactivate one plugin, reload Site Health, and repeat until the error returns.
- If the error stays with all plugins off, switch to a default WordPress theme and check again.
If you have server access, WP-CLI gives the same result faster. The WP-CLI deactivate command supports wp plugin deactivate --all, and the DreamHost WP-CLI guide lists the same command for managing plugins from a shell.
The Health Check plugin adds a Troubleshooting Mode that deactivates plugins and switches the theme for your browser session only, so visitors see the site as normal. Learn WordPress has a short lesson on the Site Health screen that walks through the Status and Info tabs.
How do you fix permalinks when the REST API returns a 404?
Go to Settings → Permalinks and click Save Changes, which rebuilds the rewrite rules that route /wp-json/ requests.
Saving permalinks flushes the rewrite rules, so requests to /wp-json/ reach WordPress again instead of returning a 404. This is the first fix to try when the API worked before and stopped after a move, a migration, or a server change.
If the 404 stays after saving, the server may not be applying the rewrite rules. The Site Health Info tab shows your permalink structure and whether pretty permalinks are in use, which helps your host confirm the setup.
Ask your host to check the server rewrite configuration if saving permalinks does not fix the 404. Do not edit server config files yourself unless you know how to restore them.
How do you check if a firewall or Cloudflare rule blocks /wp-json/?
Check your security plugin and firewall logs for a blocked request to /wp-json/, then allow your server's own requests to that path.
Kinsta notes that a Cloudflare firewall can block legitimate requests to the REST API. If you use Cloudflare, look for a rule that matches /wp-json/ or /wp-admin/ and blocks or challenges it.
Cloudflare's own WAF documentation shows a custom rule that blocks requests to /wp-admin/ from IP addresses that are not on an allowlist. A rule written too broadly can catch API requests as well, so check which rule fired before you change it. See the Cloudflare WAF custom rule example.
Narrow the fix to the path that needs it, such as an allow rule for /wp-json/ from your server's IP address. Do not switch the whole firewall off, since that removes protection from every other path too.
How do you use debug logging to find the PHP error behind it?
Turn on WP_DEBUG with logging to a file, reproduce the error, then read wp-content/debug.log for the fatal error.
Back up your site first. Our guide on how to back up WordPress covers a full backup before you edit config files.
Add these lines to wp-config.php, before the line that reads “That's all, stop editing! Happy blogging.”:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
The Debugging in WordPress handbook gives this exact set of lines. With WP_DEBUG_LOG set to true, errors are saved to debug.log in the content directory, usually wp-content/debug.log.
Reload the Site Health page, then open the log and look for a fatal error or a warning that names a plugin file. PHP notices printed on screen can also break a JSON response, so keeping WP_DEBUG_DISPLAY false matters while you check.
Turn WP_DEBUG back to false when you have the answer, and delete the log if it holds paths or other details you do not want on the server. The handbook warns against using debug tools on live sites, so keep this window short.
How do you know the error is fixed, and when should you contact your host?
Reload Tools → Site Health and confirm the REST API item shows as passed, then save a post in the block editor to confirm it works.
A passed test means the request returned a 200 response with valid JSON. Save a draft post and publish a test post if you can, since the editor is the feature that fails first when the API breaks.
Contact your host if the error stays after you have saved permalinks, tested plugins, and checked firewall rules. The cause may sit on the server, such as DNS that does not resolve your own domain, a firewall that blocks the server's own IP, or an SSL problem.
Send the host the exact error text from Site Health, the endpoint tested, the response code, and a copy of the Site Health Info tab. The Info tab has a button that copies all site info to the clipboard, which gives support the PHP version, server details, and plugin list in one paste.
What mistakes should you avoid?
Changing several settings at once, or switching off security to silence the warning, makes the error harder to find and can leave the site open.
- Do not disable the REST API or turn off your firewall to clear the warning, since the block editor and many plugins need the API.
- Do not edit
wp-config.phpon a live site without a backup, and do not leaveWP_DEBUG_DISPLAYon, since errors then show to visitors. - Do not deactivate plugins on a live site without noting which ones were active, or use Troubleshooting Mode instead.
- Do not ignore the error because the front of the site loads, since scheduled posts and background updates can fail quietly.
- Do not change permalinks, plugins, and firewall rules in one go, since you will not know which change fixed it.
Frequently asked questions
Can I ignore the REST API error if my site looks fine?
No. The front of your site can load while the editor is broken, because pages are served directly while saving goes through the API. Scheduled posts, background updates, and plugins that use the API can also fail quietly. Fix the error even if visitors see nothing wrong, and use the response code in Site Health to find the cause.
Does the REST API error mean my site was hacked?
Not by itself. The error usually comes from a firewall rule, a plugin conflict, broken permalinks, or a server problem. Check the response code first, then look for a recent plugin change or firewall rule. If you also see unknown admin users, strange files, or content you did not add, treat that as a separate security problem and clean the site.
Why does the REST API error appear only on my staging site?
Staging sites are often password protected with HTTP Basic Auth, and the server's own request is refused with a 401 unless the password is passed or the server IP is allowed. The Site Health test does pass Basic Auth credentials when they are set, so check that the staging password is active and that the server can reach its own domain. Remove the password or allow the server IP if the test keeps failing.
Will switching themes fix the REST API error?
Only if the theme is the cause. Switch to a default WordPress theme and reload Site Health to test it. If the error clears, the old theme was breaking the API response, so check it for PHP errors or contact the theme author. If the error stays, switch back and keep looking at plugins, permalinks, and firewall rules.
How long does it take to fix the REST API error?
Saving permalinks or fixing a firewall rule can take a few minutes. Finding a plugin conflict takes longer, since you reactivate plugins one at a time and re-check Site Health after each one. A server problem, such as DNS or a host firewall, can take a day or more because only the host can fix it.
Does the REST API error affect my search rankings?
It does not block search engines from reading your pages directly. It can still hurt your site over time, because failed scheduled posts, broken background updates, and an editor you cannot save in slow down publishing. Fix the error, then check that scheduled posts publish on time.
Sources
- WP_Site_Health::get_test_rest_availability() WordPress Developer Resources
- Site Health screen WordPress.org Documentation
- REST API Handbook WordPress Developer Resources
- Debugging in WordPress WordPress Developer Resources
- How to Fix the WordPress Updating Failed and Publishing Failed Errors Kinsta
- Require known IP addresses in site admin area Cloudflare Docs
- wp plugin deactivate WordPress Developer Resources
- WordPress wp-cli overview DreamHost Knowledge Base
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
