Enabling the REST API

I’m new to REST API development in WordPress.  There, I’ve said it.

I’m not new to PHP site development though.  I’ve built simple sites, complex sites, one off scripts and so on.  I can debug with the best of them with var_dump() and die().

My learning the WordPress REST API started with a project about loyalty rewards.  Now I’m starting to see other uses where data stored in WordPress can either be pushed in or pulled out.

I’ve read all the docs on https://developer.wordpress.org/rest-api/.  I’ve scoured for all the posts by Josh Pollack on Torque Magazine.

Either I missed this one detail or it’s always assumed.

With this new project in my head, the goal is to send data about WordPress sites to a central repository of information…  SharePoint.   It’s not Dawson College’s goal to have everything in Microsoft SharePoint but this seemed like a good place for it.  It’s just information about WordPress sites that can be presented in a meaningful way.

The goal with this project is to take data from all the site we got, 72 at the time of writing and put it into SharePoint.  I want to have accessible to us a listing of all the sites we have.  Whether they’re in development, production, staging or archived.  What version of WordPress core, what plugins are installed. What themes are install and/or active.  Also, the users.  I wanna have a list of users on every site.  This means when a plugin becomes seriously vulnerable, we can go patch it.  When we need to remove a user across the board, we know where they exist.

Now, I know there are solutions out there that do this already.  SASS based solutions and self hosted products.  We can’t go with the SASS solution for the data confidentiality reasons and I’m not a fan of what the self-hosted products are doing.  So as we like to do at Dawson College, we build things ourselves sometimes cause we don’t want the bloat and reliance of 3rd party products.

So the first thing I did for this new project, setup a brand new site on our dev server and get going.  I want our Intranet server to be able to query all our sites and get the data and put it into SharePoint.  The Intranet server will have the SharePoint credentials and all WordPress would have to do is just give out the data.

By now, I’ve got a basic WordPress site operational with no plugins and very little customisation.  I started to reuse code from other projects and the developer.wordpress.org website for the base of this new plugin.

With the routes in place, I’m trying to access the data that’s supposed to be coming up in the browser and all I’m getting is the home page.  Hello World!  I’m trying to figure out what’s going wrong and why the REST API isn’t taking over at the very least not spitting out debug information.

What must have been at least an hour or more, I went into WordPress and flushed the permalinks.

After that, things started to work and debug information filled the page and it unleashed the power of the REST API.  So, moral of this story – make sure your permalinks are set before starting any REST API work!