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.
- Login to your WP site and add the WP REST API Plugin
- Activate the plugin
- 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
- Open your favorite BI or data analysis tool.
Note: For this example I’m going to use Power BI. - 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
And here’s how to quickly parse the JSON and get started
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.
Leave a Reply