Integrating Your API with My WordPress: Tools & Words of Wisdom

API’s are cool. They allow you to interface with other people’s data and use it with your own site. This enables you to provide a much deeper/richer experience for your customer base than if your site content was solely reliant upon your manual input of all content.

Some examples of APIs that are regularly used in the WordPress industry are payment gateways such as PayPal and Stripe and article feeds such as Reuters. The primary gist of these types of services are that you provide the service with some parameters and it returns a set of data in a pre-defined format. You then read in the format and parse the data to be used in your own way.

Each service offered by various companies will have their own way of defining the data and their own way of delivering the data and it will be up to you, as a developer, to be able to read in that information returned and make sense of it in a useable format. Some various types of ways to receive data from an API is usually RESTful or SOAP based services. RESTful services include XML and JSON and have no set standards. A SOAP based service is a protocol with standards using XML for communication over HTTP. These are subtle and important differences when integrating an API into your WordPress site.

According to Google Trends information, Soap is on a steady decline or even leveled off very low in terms of usages, while REST has increased exponentially.

Screen Shot 2015-03-03 at 5.31.41 PM

 

The reason I bring this up is because sometimes you don’t always have to invent the wheel when it comes to importing content from an API, especially if it is a RESTful XML file that can take a URL to return information. WordPress developers have worked hard to create a series of tools that will enable you to make magic on your website, even as a developer.

Here are a list of tools that would get basic APIs up and running on your site with a little careful planning and a few clicks and keyboard strokes.

  • WPAllImport
    This tool imports any XML or CSV file into your WordPress site. It is a premium plugin with an annual fee, but if your site depends heavily on external data being imported into it, the fee should be worth it.
  • Custom Post Type UI
    CPT UI allows you to create an unlimited amount of custom post types and custom taxonomies. This is especially useful if you are not doing ‘post’ or ‘page’ based work and need much fine control over the type of content that you are entering. For instance, if your website is a catalog of cars built in the 1900’s, you might want to import the data as ‘autos’ instead of ‘posts’ or ‘pages’. This gives you that granular access to be able to fully define your content pieces. This plugin is completely free and also completely worth it.
  • Advanced Custom Fields
    ACF is another premium plugin that is completely worth the price tag. This allows you to have even more granular control over the admin interface and ‘post meta’ of your site for each post. There are even add-ons that you can purchase that will give you special access to the WP Options table via the WP Admin. It has personally saved me hours and hours of coding up meta boxes.

With these three tools, you should be equipped to import and control the most basic API in XML format out there. Of course, if the APIs are more than a simple XML call, you will probably not be able to use WPAllImport and will need to develop a custom solution. An example of a series of more complex APIs are those that require you to call a list of ALL of one type of thing and, based on the specific ID of one of the items in that list, make a second call to retrieve the API for the specific data in that list. An example of this would be getting all automobile makers in one call-back and having to send a second request to get all autos of a specific maker with a specific ID. Those can be a sinking rabbit hole and unless your name is Alice, I don’t recommend you follow.

And of course if you need help with that custom solution, send an email, I’ll be happy to see if I can recommend a solution for the API you want to integrate.

So to sum it all up: integrating a third-party API can be very easy to do if the API is in XML and is a simple URL call. It can get a little more crazy if there are multiple calls to multiple parts of an API that is XML based.

Of course there is a third type of API more like the Facebook API which requires the installation of libraries. That’s a different topic for a more advanced entry.

What are some of the tools you use to import information from APIs into your website? What do you think of the tools listed above? Do you have a strong preference for a different tool that accomplishes the same things? I want to hear!

1 thought on “Integrating Your API with My WordPress: Tools & Words of Wisdom

  1. Pingback: Whoops! I didn’t mean to send that email. | tabby chapman

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.