More fixes

WordPress Site Health: "The REST API encountered an error" and "Your site could not complete a loopback request"

Tools, Site Health lists two critical issues that usually arrive together. They look alarming, and they matter: the block editor, scheduled posts, plugin and theme file editing, and automatic updates all rely on your site being able to call itself. Your content is fine. Something between the site and its own address is refusing the call. Here is how to find what, and the fix for each case.

What the owner sees

harborbakery.example/wp-admin/site-health.php

What the checks found


  

Find out which case it is (five minutes)

  1. Read the exact error under each issue. Click the issue in Site Health. The line after "Error:" names the cause: cURL error 28 (time-out), cURL error 7 or Could not resolve host (the server cannot find or reach its own address), 401/403 (something is refusing the call), or 500 (PHP crashed while answering).
  2. Open the REST API yourself. Visit /wp-json/ on your site. A long page of JSON means the API works from outside, so the problem is the server calling itself. A 404 means pretty permalinks or the server rules are wrong. A 403 or a login box means a security layer.
  3. Is the site behind a password? Staging sites and "coming soon" setups often use HTTP basic auth. Your browser knows the password; the server calling itself does not, so every loopback gets 401.
  4. Did it start after a plugin, a move or a new firewall? Security plugins, "disable REST API" plugins, Cloudflare rules and a recent domain or host change are the usual causes.

The fixes, by case

  1. cURL error 28 (timed out): the self-call took longer than 10 seconds. Often a plugin starts a PHP session (session_start()) and holds it, so the second request waits for the first. Find the plugin with the Health Check & Troubleshooting plugin's troubleshooting mode, which disables plugins for your login only. A slow site can also do it: see the slow-admin fixes.
  2. 401 on a password-protected site: allow the server's own IP past the basic-auth rule, or switch the protection off on the live site. A "coming soon" plugin that blocks /wp-json/ for logged-out visitors needs its REST option turned on.
  3. 403 from a security plugin or firewall: a setting such as "disable REST API" or "block XML-RPC and REST" is on, or ModSecurity / Cloudflare blocks the request. Allow logged-in REST requests in the plugin and whitelist the server's own IP in the firewall rather than turning protection off.
  4. cURL error 7 or "could not resolve host": the server cannot reach its own domain. Common right after a move: DNS points at the new host but the server still resolves the name to the old IP, or the host blocks connections from the server to itself. Your host can add the domain to the server's hosts file or allow the loopback; this is a one-line ticket.
  5. 404 on /wp-json/: go to Settings, Permalinks and click Save without changing anything. That rewrites the server rules. On Nginx, the host must have the standard WordPress try_files rule.
  6. cURL error 60 (SSL certificate): the server's own certificate bundle is out of date or the site's certificate is incomplete. See the cURL error 60 fix.
  7. 500 or a PHP error in the reply: a plugin or theme crashes when called by the API. Turn on WP_DEBUG_LOG, run the Site Health test again, and read wp-content/debug.log for the file named.

What you see, what it means, what it needs

What you seeWhat it meansUsual fix
cURL error 28: Operation timed outThe self-call waited over 10 secondsFind the plugin holding a PHP session
Unexpected result 401Basic auth or "coming soon" blocks the serverAllow the server's IP or the REST path
Unexpected result 403Security plugin or firewall refuses itAllow logged-in REST, whitelist own IP
cURL error 7 / could not resolve hostServer cannot reach its own domainHost fixes the loopback or hosts file
/wp-json/ gives 404Rewrite rules are missingRe-save Permalinks; Nginx try_files
Unexpected result 500A plugin crashes on the API callRead debug.log, update or replace it

What not to do

Most cases are one plugin setting or one firewall rule. If both issues are still red, that is what the box below is for. Related: cURL error 28, cURL error 60, Missed scheduled posts, "Not a valid JSON response".