A course on the WordPress Rest API failed short to list out all endpoints for the WordPress API. These routes will be configured below, and how to get them using Python will be explained as well.
First, a install of the requests module for python is required, for the sake of your sanity.
If its not already installed run the command:
pip install requests
Now open up a new Python file and name it WordPressRestApi.py or anything you’d like really.
Now to use the requests module, make the first line in your Python script:
After that, invoke the ‘get’ method of requests by using the following statement:
r = requests.get('http://wordpresssite.com/wp-json/wp/v2')
This statement will return a json blob, ready for you to mold.
The blob will come in dictionary format only if you call the requests .json method on the response:
JSON = r.json()
Now, looping through the newly instantiated dictionary of name JSON, you’ll be able to get all the routes.
for i in JSON: print i
This will return three items of: routes, _links, and namespace
The one relevant to this article will be routes. So just switch the for loop to
for i in JSON['routes']: print i
This will return the following:
/wp/v2/statuses /wp/v2/taxonomies/(?P<taxonomy>[\w-]+) /wp/v2 /wp/v2/categories/(?P<id>[\d]+) /wp/v2/posts /wp/v2/media /wp/v2/tags/(?P<id>[\d]+) /wp/v2/users/me /wp/v2/types/(?P<type>[\w-]+) /wp/v2/categories /wp/v2/statuses/(?P<status>[\w-]+) /wp/v2/comments/(?P<id>[\d]+) /wp/v2/posts/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+) /wp/v2/users /wp/v2/pages/(?P<id>[\d]+) /wp/v2/tags /wp/v2/pages/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+) /wp/v2/pages /wp/v2/types /wp/v2/comments /wp/v2/settings /wp/v2/pages/(?P<parent>[\d]+)/revisions /wp/v2/taxonomies /wp/v2/users/(?P<id>[\d]+) /wp/v2/media/(?P<id>[\d]+) /wp/v2/posts/(?P<id>[\d]+) /wp/v2/posts/(?P<parent>[\d]+)/revisions
Putting Everything Together
import requests r = requests.get('http://1000daysofcode.com/wp-json/wp/v2') json = r.json() for i in json: print i
Those are all the routes the default WordPress API supports, that you can bend to your will.