Skip to content
WordPress3 min read

WordPress REST API error and "The response is not a valid JSON response"

The REST API encountered an error

Short answer

A REST API error appears when WordPress doesn't get a clean JSON response from your site's /wp-json/ path. Common causes are broken rewrite rules in .htaccess, a security plugin blocking the API, a firewall rule rejecting the request, or a PHP warning printed into the response. Open /wp-json/ in your browser first, then re-save permalinks.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What the error means
  2. Common causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

WordPress relies on an internal API called the REST API, served under /wp-json/. The block editor saves posts through it, and WooCommerce and many plugins depend on it. That’s why the failure shows up in several places: under Tools › Site Health, or when you click Update in the editor.

What the error means

The admin sends a request to a path such as /wp-json/wp/v2/posts/123 and expects JSON back. If the request returns an error code (403, 404 or 500), or a response containing HTML or a PHP warning, you see one of these:

  • The REST API encountered an error or The REST API encountered an unexpected result in Site Health.
  • Updating failed. The response is not a valid JSON response. or Publishing failed. in the editor.

Common causes

  • Missing or broken rewrite rules in .htaccess, so /wp-json/ returns a 404.
  • A security plugin disabling or blocking the REST API.
  • A web application firewall rule rejecting the request with a 403, especially when the post contains code or text that looks like a query.
  • PHP warnings printed on screen, landing before the JSON and corrupting it.
  • Mismatched site addresses in settings (http vs https, www vs non-www).
  • The domain pointing at another server, or a password-protected folder, so the site’s request to itself (loopback) fails.

How to fix it

  1. Open the API directly: visit https://example.com/wp-json/. You should see text starting with {"name":. A 404 means a rewrite problem; a 403 means something is blocking it.
  2. Try the fallback route: open https://example.com/?rest_route=/. If this works while /wp-json/ doesn’t, permalinks are the cause.
  3. Re-save permalinks: under Settings › Permalinks, click Save Changes without changing anything, and WordPress rewrites its rules. If .htaccess is damaged, restore the default block in Files › File Manager:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
  1. Read the real response: in the editor, open developer tools (F12) › Network, click Update, and open the failed wp-json request. You’ll see the status code and the response body, which may be a PHP warning naming the plugin.
  2. Hide warnings from output with define( 'WP_DEBUG_DISPLAY', false ); in wp-config.php, as described in Cannot modify header information.
  3. Match the site URLs: under Settings › General, WordPress Address and Site Address must match and both start with https://.
  4. Test plugins: temporarily disable security and caching plugins, or use the Troubleshooting mode of the Health Check plugin, which disables plugins for your session only while visitors see the normal site.
  5. If the 403 comes from the firewall, see ModSecurity 403 and send support the time and URL.
  6. If the loopback request fails, make sure the domain points to your current server; see domain not pointing to hosting.

Prevention

  • Don’t disable the REST API entirely; restrict only sensitive routes.
  • Keep display_errors off on the live site.
  • After a migration or domain change, re-save permalinks and open Site Health.

On ArabyHost

The LiteSpeed web server reads .htaccess, so WordPress’s default rewrite rules work as they are. Imunify360 protects sites from malicious requests; if a legitimate editor request gets blocked, send support the time and URL so they can check the rule. The Araby AI assistant reads the error log and explains why the request failed. More on our WordPress hosting.

FAQ

Why can't I save posts because of the REST API?

The block editor (Gutenberg) saves everything through the REST API. If that request fails or returns something other than JSON, you get "Updating failed. The response is not a valid JSON response." and the change isn't saved.

Does disabling the REST API make the site safer?

Turning it off completely breaks the editor and many plugins, WooCommerce included. Restrict specific routes for logged-out visitors, such as the users list, instead of switching the whole API off.

What does "Your site could not complete a loopback request" mean?

Your site couldn't connect to itself, which WordPress needs for scheduled tasks and error checks. Usually the domain points to another server, or a firewall or folder password blocks the request.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.