11

I'm brand new to Wordpress and I would like to use the JSON API plugin.

So I put it in my plugin repository and I activated it but when I try to display the Json response by accessing the http://localhost/wordpress/wp-json/posts url I get a 404 error.

I'm probably missing something but according to the documentation it should be that simple. Any idea of what am I doing wrong?

Simon
  • 6,025
  • 7
  • 46
  • 98
  • This question has already been answered [here](https://stackoverflow.com/questions/23842235/wordpress-jsonapi-wp-json-was-not-found-on-this-server/52719375). – Aurovrata Sep 16 '22 at 13:52

5 Answers5

9

It is an mod_rewrite issue.

Reason is one of these in your .htaccess:

  • not existing
  • wrong permissions
  • screwed up

Try the htaccess documentation on Wordpress for your .htaccess:

## BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress
leymannx
  • 5,138
  • 5
  • 45
  • 48
Eric
  • 91
  • 1
  • 1
  • Thank you so much. Worked perfectly for me. Everything was working fine started facing issue suddenly only because of .htaccess file. Thanks a lot for saving my time. – user2067787 Dec 09 '19 at 12:26
  • when .htaccess, permissions and php extensions are ok, we can play with site configs. In sites-available conf folder I just added `` with `Options Indexes FollowSymLinks` ,`AllowOverride All`. `Require all granted`. Reloaded apache and not 404 errors are gone. This solves elementor 404 error on `/wp-json/elementor/v1/globals` – Junior Mayhé Feb 16 '22 at 21:44
6

Old question and answer, but for anyone coming here recently via search results (like me), /wp-json/posts should at least bring a JSON result (albeit still a 404 error), and /wp-json should list some available routes in JSON.

If it doesn't (e.g. it shows an Apache or other 404 error page), it's probably a permalinks issue

ono2012
  • 4,967
  • 2
  • 33
  • 42
Robert Dundon
  • 1,081
  • 1
  • 11
  • 22
  • 1
    You may need to use a different permalink structure. Encountered the same issue using the wordpress docker compose image. Use anything other than the query string method. – HSchmale Jan 28 '19 at 17:16
  • If I could I would spam the +1 button. This was why my plugin didn't work on a fresh installed wordpress. – Vizjerei Aug 27 '21 at 11:19
4

You have the wrong address. According to the documentation, the following are valid links:

Implicit mode examples:

Explicit mode examples:

With user-friendly permalinks configured:

Source: https://wordpress.org/plugins/json-api/other_notes/

So in your case you should use http://localhost/wordpress/api/get_recent_posts/

David Brossard
  • 13,584
  • 6
  • 55
  • 88
  • 1
    Thanks, it works! I had read on the dashboard of Wordpress in the plugins page : "Want to get your site's posts? Simply send a GET request to /wp-json/posts" that's why I did this. – Simon Nov 20 '14 at 00:49
1

/wp-json/elementor/v1/globals - 404 error

Just update the plugin if any update is available and deactivate it first and then re-activate it again. The problem will be solved.

When we activate the Elementor plugin then this plugin creates some essential files for editing, so when we will re-activate it then it will re-create all essential files and our problem will be solved. Thanks

0

It may depend on whether you have NGinx or Apache. On some hosts with Plesk if Nginx is used, Plesk does not create or re-create the .htaccess file, but for WP it must be present. If it's not there, just recreate it with the standard WP settings https://wordpress.org/support/article/htaccess/ as mentioned in one of the previous answers.

A workaround (insecure) is to create directories and files /wp-json/elementor/v1/globals with {} like Json standard, elementor will work the same, but I don't recommend doing that.