Data Insights with the WordPress REST API

WordPress is moving closer to becoming a fully-fledged application framework. It has always been easy to publish with WordPress but accessing your data from external systems was often very difficult.

But what is WordPress REST API anyway? Well here’s an excellent explanation but, to simply for our purposes, the WordPress API allows us to read data from our WP site in another application.

As many have noted, the upcoming release of WordPress 4.4 will ship with a large part of the new API. In the meantime, we can take advantage of the REST API by using the REST API feature plugin to gain insights into our WordPress sites by connecting to a business intelligence (BI) tool. Some common BI tools include Power BI, Tableau, Excel, and Zoho Reports although there are several good open source alternatives.

In this post, I will show you how to use the WordPress REST API to pull data into a BI tool. Specifically, we’re going to get all site posts with an external system and analyze them.

  1. Login to your WP site and add the WP REST API Plugin
    Add New Plugin
  2. Activate the plugin
    wp_api_activate
  3. Now we’ll need to determine the API endpoint to pull the data from. The REST API allows us to read or manipulate data using HTTP with these actions: GET, POST, PUT, DELETE. For our purposes, we are only interested in GET (i.e., we want to use our BI tool to get data from WP).You can read the full API documentation here but, for this example, we’re going to simply look at retrieving posts.
    Get All Site Posts
    http://www.yoursite.com/wp-json/posts
    Example: http://digitalborn.org/wp-json/posts
  4. Open your favorite BI or data analysis tool.
    Note: For this example I’m going to use Power BI.
  5. Use the web connector option in the BI tool.
    Power BI -> Click on Get Data and then Web
    Tableau -> Click on Web Data Connector
    Zoho Reports -> Schedule Import from Web Feed
    Excel -> Click on Data and From WebHere’s an example from Power BI of getting data from the end point
    Get data into Power BI from WP

And here’s how to quickly parse the JSON and get started
Parse JSON data in Power BI for data analysis

 
Important: this is for public posts. If you have posts that are in draft status or private and you want to retrieve these for analysis, you will need to authenticate when you connect to the API endpoint. The BI tool will automatically prompt you to authenticate. For testing and development you can use the Basic Authentication plugin. For production environments, you should use the OAuth plugin.


Comments

3 responses to “Data Insights with the WordPress REST API”

  1. Chris Avatar
    Chris

    This is awesome – What other data can you access via this method? Just posts or can you access any part of the database?

  2. Chris, you can currently access almost any data that’s part of a standard WP instance including posts, comments, users, tags, categories, etc. There are also many extensions on WP REST API that allow you to access data from plugins. For example, Formidable (a form builder plugin) has an Formidable API plugin that takes advantage of the WP REST API. By activating the Formidable API add-on you can access data submitted to a form. I’ll create a guide later this week on how to do this. You can see some additional extensions and a reference here:

    http://v2.wp-api.org/reference/

  3. Chris Jones Avatar
    Chris Jones

    Thanks Nathan 🙂

Leave a Reply

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