12

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?

1
  • This question has already been answered here. Commented Sep 16, 2022 at 13:52

5 Answers 5

10

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
Sign up to request clarification or add additional context in comments.

3 Comments

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.
when .htaccess, permissions and php extensions are ok, we can play with site configs. In sites-available conf folder I just added <Directory /var/www/html/mysite/> 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
worked perfectly fine for a standard wordpress installation (version 6.7) without modifications. In my case, the wordpress section was missing in .htaccess.
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

2 Comments

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.
If I could I would spam the +1 button. This was why my plugin didn't work on a fresh installed wordpress.
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/

1 Comment

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.
2

/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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.