WordPress REST API Routes List

Wordpress logo in water

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.

Set Up

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:

import requests

The Program

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

The Results

This will return the following:



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.

Happy Coding!

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *