Like YQL? Try it with the ProgrammableWeb API

Sebastian Spier, February 8th, 2012

APIs are inherently difficult to learn for developers. The ProgrammableWeb API is no exception to this rule either. In this article we will show some examples of how Yahoo’s YQL can be used make developer’s life a bit easier when using the ProgrammableWeb API.

The main difficulty with APIs in general is that they require the developer to create and remember a number of cryptic URLs via which certain data can be retrieved from the API. Another issue is, that often fairly simple data requests need to be expressed in multiple API calls, which then have to be merged by the developer itself in order to further use this data in his application.

Yahoo Query LanguageSo what can be done to overcome this misery? Yahoo’s YQL tries to address this by converting API calls into SQL-like commands, which are somewhat more human readable. Let’s look at a couple of examples of how YQL can be used to interact with the ProgrammableWeb API.

Example 1: API Mashups

To show the mashups that are using a certain API, you need to send this call to the ProgrammableWeb API:

http://api.programmableweb.com/mashups?api=google-maps&apikey=YOUR_API_KEY

In YQL, you get the same data with this call:

SELECT * FROM pw.mashups
WHERE apis=“google-maps” AND apikey=“YOUR_API_KEY”

While this is not shorter than the bare API call, it tells you a bit more about what you are requesting and from where. Lets have a look at another example.

Example 2: ProgrammableWeb Members from San Francisco

To find ProgrammableWeb members from San Francisco, you need this API call:

http://api.programmableweb.com/members?q=San%20Francisco&apikey=YOUR_API_KEY

Expressed in YQL this is:

SELECT * FROM pw.members
WHERE query=“San Francisco” AND apikey=“YOUR_API_KEY”

This YQL query is very similar to the one in example 1, with just one minor twist. When defining the YQL table for an API, YQL allows for renaming of parameters in order to improve the readability of the API calls. In this case I have renamed the q parameter to query, to show this.

Example 3: ProgrammableWeb Member Data

YQL shines even more in areas where it can provide an abstraction layer to simplify queries in the original API. For example, in order to retrieve the member data of 3 different ProgrammableWeb members (usernames: jmusser, duvander, spier) you have to issue 3 API calls:

http://api.programmableweb.com/members/jmusser?apikey=YOUR_API_KEY

http://api.programmableweb.com/members/duvander?apikey=YOUR_API_KEY

http://api.programmableweb.com/members/spier?apikey=YOUR_API_KEY

With YQL you can do all in one call:

SELECT * FROM pw.members
WHERE (username="jmusser" OR username="duvander" OR username="spier")
AND apikey="YOUR_API_KEY"

Try it Yourself

Hopefully but now I got you a bit excited about YQL and the ProgrammableWeb API, and you want to try it out.

I have created an initial set of YQL tables for the ProgrammableWeb API, which can be found in this github repository. These YQL tables are not complete yet, meaning they do not cover all API calls but it is a good start. In order to try out the YQL calls in this article, you need to do this:

  • Sign-up for a ProgrammableWeb user account (if you don’t already have one)
  • Request a developer key (make sure to state your ProgrammableWeb username)
  • Load the ProgrammableWeb YQL tables into the YQL console
  • Copy and paste one of the YQL examples from this article into the console and try them (of course using your API key)

Have fun while trying this out, and post comments about your experience with YQL and the ProgrammableWeb API below. Looking forward to hear from you.

Both comments and pings are currently closed.

One Response to “Like YQL? Try it with the ProgrammableWeb API”

February 11th, 2012
at 2:29 am
Comment by: Sebastian Spier

An extra tip for companies looking to build or extend their own API:

Try to create YQL tables for your API. If that turns out to be difficult, then you have probably designed a very non-standard API.

Follow the PW team on Twitter

ProgrammableWeb
APIs, mashups and code. Because the world's your programmable oyster.

John Musser
Founder, ProgrammableWeb

Adam DuVander
Executive Editor, ProgrammableWeb. Author, Map Scripting 101. Lover, APIs.