Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress JSON API returns only 404 errors

Tags:

json

wordpress

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?

like image 877
Simon Avatar asked Nov 20 '14 00:11

Simon


People also ask

How do I fix REST API 404?

You fix this by opening the listen step in your VSM file, and changing the base path in there, so you don't get a 404 error. You could change that to "/api/" so any api requests are dealt-with, or "/api/retrieveId/" so only retrieveId messages are dealt-with, or "/" so all requests are dealt-with.

Does WordPress use JSON?

The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects.


3 Answers

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
like image 111
Eric Avatar answered Oct 10 '22 16:10

Eric


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

Implicit mode examples:

  • http://www.example.org/?json=1
  • http://www.example.org/?p=47&json=1
  • http://www.example.org/tag/banana/?json=1

Explicit mode examples:

  • http://www.example.org/?json=get_recent_posts
  • http://www.example.org/?json=get_post&post_id=47
  • http://www.example.org/?json=get_tag_posts&tag_slug=banana

With user-friendly permalinks configured:

  • http://www.example.org/api/get_recent_posts/
  • http://www.example.org/api/get_post/?post_id=47
  • http://www.example.org/api/get_tag_posts/?tag_slug=banana

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

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

like image 23
David Brossard Avatar answered Oct 10 '22 16:10

David Brossard


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

like image 27
Robert Dundon Avatar answered Oct 10 '22 16:10

Robert Dundon