We’ve come a long way so far in our six-part REST API series. From pretty much a standing start, we’ve managed to introduce the basic concepts of the technology, and get a small interactive app up and running (with a little help from React).
Along the way, we’ve hopefully proven that even non-technical WordPress users can already start getting their feet wet with the programmatic power behind the next generation of the platform. The future of WordPress is not going to be about tiny Thoreau quote apps, however. It’s going to largely centre around how the REST API helps WordPress smoothly integrate with the rest of the online world.
To close out our series, we’ll take a peek at what that type of integration might look like, fire up a very simple practical example, and finish off with some quick resources to help you explore further on your own.
The Wider Programmatic World Awaiting WordPress
If you’ve used WordPress for any length of time at all, you’ve almost certainly taken advantage of existing third-party integrations in the form of plugins. You might have added MailChimp into the mix, experimented with Google Analytics options, or taken advantage of any of the other popular third-party app plugins that are out there.
Though the sophistication of many of these solutions to date has been impressive, they’ve always been held back by a fundamental problem on the WordPress side of the equation. From a technical point of view, the lack of a stable and reliable native API in WordPress has historically put developers on shaky ground in terms of stability, testing, and adding new features.
The REST API effectively removes those obstacles and places WordPress on an equal footing with other applications that have a stable, well-defined API. Remember, we’ve barely settled into the starting blocks at this stage – the real race is very much still to be run. There’s an excellent chance that we’ll see something of a Cambrian explosion in terms of third-party integrations over the next two to five years. Put simply, if it can be integrated, it more than likely will be.
Developers are naturally already chomping at the bit, but it can be tricky for mere mortals to get a sense of the opportunities on offer here. Let’s take a quick crack at fixing that with the aid of a demo example using the power of Zapier.
Dipping a Toe Into the Integration Waters With Zapier
Zapier is a handy bit of online plumbing that offers an excellent insight into the opportunities opened up by applications communicating directly with one another via API. It’s far from a technically daunting online playground that you can use to experiment with creating your own workflows and integrations between popular apps.
The basic idea is straightforward – Zapier acts as a smart bit of middleware that elegantly exposes underlying APIs, and enables you to connect disparate apps without having to write a line of code. You can either select from existing integrations (known as ‘Zaps’ in Zapier lingo), or create entirely new ones from the 500+ apps that are supported.
Even a quick scan through the popular apps supported should be enough to pique your interest here; the vast majority of day-to-day, online business tools are covered in one way or another. Luckily enough for our purposes, WordPress is also in the mix.
WordPress-Specific Options in Zapier
If you have a quick look at the Zapier WordPress page, you’ll see an impressive list of 100 handy existing WordPress integrations, covering everything from Buffer to Slack. Look a little further down the page, and you’ll see the WordPress-specific options available to us, split out across two core categories:
- Triggers: These are events that can happen within WordPress which then function as a spur to further action. As you’ll see from the list, many of the basics are covered here – the HookPress plugin opens the door to those that aren’t.
- Actions: These are things you can ask WordPress to do in response to an external event in another application. The options here are more pared down – we’re limited to creating a new post or adding new media.
The list of exposed functionality available here is substantially smaller than that offered by the REST API proper, but the territory is conceptually similar. We’ve also got a nice simple interface to play with that doesn’t require custom coding. Let’s take it for a spin by hooking it up with what’s effectively the largest active REST API project in the WorldPress world: Calypso and WordPress.com.
Connecting Zapier To Pinterest
We’ll leave our existing local WordPress/React app behind at this stage, and set up a quick free site on WordPress.com. If you’ve been keeping an eye on the commercial arm of the platform of late, you’ll know that its admin backend recently migrated to being a REST API-powered React application. We’ll take Zapier for a quick spin and see if we can automate feeding some useful information into it.
Here’s what we’re looking to do: browse and flag potentially interesting quotes on Pinterest, and then have their details automatically imported into WordPress without us having to do it manually.
We start by creating a new Zap in Zapier:
We then select Pinterest and New Pin as the trigger:
We can then easily select and authenticate our particular Pinterest account:
We then have the option of selecting a particular board to target. In our case, there’s an existing board called Possible Quotes already set up:
We’re then given the convenient option of actually testing that the connection is working:
In our case, everything seems hunky-dory up to this point, so we can now move on to the WordPress side of things.
Pulling Data Into WordPress From Zapier
We’re now on the action side of the equation in Zapier. We kick things off by selecting WordPress as the application we’ll be targeting, and Create Post as the actual action we’re after:
We then need to authenticate a site. In this case, we’re connecting to a throwaway free WordPress.com account that’s been set up earlier:
We’re then given a number of handy post options that we can specify. These are powered by the WordPress.com version of the REST API behind the scenes. In this case, we’ve kept things simple and pulled out the selected pin’s link, any notes associated with it, and the primary image URL. We’ve also set the new post to automatically have a draft status rather than publishing it:
Again, we’re kicked into a handy test sequence to make sure this will actually work:
Switching back over to our Calypso-powered WordPress.com account, we now see a new draft post listed in Latest Drafts:
A quick look at the post itself is all we need to check that it’s actually successfully brought in the requested data from Pinterest:
Once we save our new zap back in Zapier, we’ve now got an API-powered piece of kit that will merrily check our Pinterest account every five minutes and import the data we’ve specifically asked for – all without writing a single line of code!
The exploratory example we’ve covered here is necessarily basic, but it very much points the way towards one direction where WordPress will be heading with the REST API. We can expect it to power a new generation of powerful third-party integrations which enable non-technical users to create their own tailored solutions in a modular, drag-and-drop manner. If you’re still trying to absorb the implications of that, we’d strongly recommend creating a free Zapier account and exploring further on your own to get more of a feel for the future.
It’s time to finally wrap up our series! We’ve covered a lot of resources along the way, but we’d like to point you towards a few in particular to close things out and help you keep pace with REST API development in general:
- WP REST API documentation: The REST API is still a work in progress, and the official docs do a great job of getting people ramped up quickly.
- REST API-related presentations: There’s an increasingly excellent series of deep-dive talks on WordPress.tv that reward close viewing.
- Our own REST API reporting: A regular review of the latest REST API-tagged content here on the site will keep you more than up to speed!
We hope you’ve learned as much throughout the series as we did putting it together, and we’re keen to hear your feedback. Get in touch via the comments below and share your REST API-related thoughts!
Featured image: geralt.