Encountering 404 Error When Trying to Access /wp-json/ in WordPress

I’ve recently added a WordPress REST API plugin to my website, but I’m facing a challenge when trying to access the JSON endpoint. When I attempt to make a GET request to the API, it results in a 404 error.

Here’s the command I’ve been using:

$ curl -i http://mywordpresssite.com/wp-json/
HTTP/1.1 404 Not Found
Date: Mon, 15 Jun 2024 10:30:45 GMT
Server: Apache/2.4.41 (Ubuntu)
Content-Length: 287
Content-Type: text/html; charset=UTF-8

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /wp-json/ was not found on this server.</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at mywordpresssite.com Port 443</address>
</body></html>

Despite trying to access this endpoint, it’s not working, and I’m not getting the expected JSON data with the available routes. Has anyone encountered a similar situation with the WordPress REST API? Could the issue lie in the permalink settings or maybe server configurations?

Any insights would be greatly appreciated!

I encountered a similar 404 issue with the WordPress REST API as well. It’s often linked to the permalink settings being set to ‘Plain,’ which prevents the routing from functioning properly. To resolve this, navigate to Settings > Permalinks in your WordPress dashboard, and select a more suitable structure, like ‘Post name.’ Make sure to save your changes afterward. If the issue persists, you might want to try clearing your site’s cache or checking your server’s configuration, as certain server setups can inadvertently block the API endpoint.

check your wp-config.php file - sometimes there’s a line that kills the REST API completely. look for define('JSON_API_ENABLED', false); or something similar. also try hitting /wp-json/wp/v2/posts directly instead of just /wp-json/ to see if specific endpoints work while the main one doesn’t. could be a routing problem, not a total block.

Had this exact problem last month on a client site. The permalink suggestion above is solid, but there’s another common culprit - .htaccess rules. Sometimes the REST API routes get blocked by custom rewrite rules or security plugins. Check if you can access other WordPress endpoints first, like /wp-admin/ to isolate the issue. If those work fine, try temporarily renaming your .htaccess file to .htaccess-backup and test the API again. Also worth checking if your hosting provider has mod_rewrite enabled, since the REST API relies on it heavily. Some shared hosting setups disable it by default which breaks pretty much all REST functionality.