Whatever your opinion of the U.S. government might be, one thing for certain is that it's a massive warehouse of information -- information that you have access to, right now.

In this article, I'm going to use the term "API" frequently. Don't let that scare you away. API stands for "Application Programming Interface". On the web, it's a way for people to "tap into" information from other websites or web services.

Why would anyone want to do this?

I'll show you why. I'll also show you what kind of impressive information you have access to and how you can use that information to improve your daily life.

Why Use an API?

Recently, Matt explained how open APIs are changing the nature of information exchange on the web.

web-connections

APIs are how a lot of your favorite websites integrate content from Facebook, Twitter, and other popular websites. It may look like magic when you visit the Wall Street Journal and you can see what people on Facebook or Twitter are saying about the story. But the truth boils down to the exchange of data and information on the Internet via these magical APIs.

How to Tap into API Data

Do you have to be an advanced programmer to do this? No.

Thankfully there are some really useful tools via services like IFTTT or Zapier that can help you build a bridge between the information found on the web via API, and the places where you want to "import" that data -- whether it's Facebook, Slack, or even Google Drive or Dropbox.

Why is this useful? Just consider a few things this can let you do when it comes to government data:

  • Request nutrient information about food from the USDA
  • Research economic information about locations with just an SMS message
  • Research political candidates and contributions via SMS
  • Post a NASA picture of the day to Twitter or Facebook
  • Get a satellite image of any location from your phone

I will show you how easy it is to do these. In each of these examples, I use the Zapier service to automate the integration of services. I've covered Zapier before, and if you aren't familiar with the service, it's well worth a read.

Before you get started, make sure that you sign up for an API key. It takes just a few minutes and you'll receive your key via email.

Getting Food Nutrient Info from USDA

As part of the Open Data initiative, the USDA provides APIs that give you access to the Department's information about food. You can set up an automated response that lets you look up food mineral information. For example, if you're on a diet and cutting back on carbohydrates, you could use this tool.

Here's how this would work.

  1. You send an email with the name of the food you want to know about in the subject line
  2. Zapier retrieves the ID for that food from the USDA database and uses the ID to retrieve the food report.
  3. Zapier sends the report to your email.

Here's how you set it up.

First, you need to create a "zap" in Zapier that can receive your email to trigger the FDA food lookup.

food-email

Zapier lets you customize part of the email address so you can make it apply to the purpose you're using it for. Once the incoming email trigger is created, continue on to the next "zap". This will be a webhook for retrieving the ID number from the USDA database for the requested food type.

In Zapier, you'll choose the Webhook trigger, and select the "GET" option.

food-email2

The next step is to enter the URL of the data request. The USDA lets you retrieve the ID of food in their database with the following web request:

http://api.nal.usda.gov/ndb/search/?format=json&q=butter&sort=n&max=25&offset=0&api_key=YOUR_KEY

The "q=butter" is the parameter where you need to pass along the subject line of the Zapier email. In the Zapier Webhooks action, you'll see that there are fields where you can set up the URL query parameters. Near each one is an "ingredients" button that will show you the "input" from the previous trigger event (the incoming email).

food-email3

Remember to add a query field with your api_key as well.

Next, it's time to create yet another web request to the USDA to retrieve nutrient information for the requested food, using the ID you just got. To do this, the correct API request string is:

http://api.nal.usda.gov/ndb/nutrients/?format=json&api_key=YOUR_KEY&nutrients=205&ndbno=01009

It's the "ndbno=01009" field which will hold the ID, using the same "ingredients" approach used in the step above.

food-email8

You'll notice in the parameter list in the URL link above, there is a single nutrient type listed. You can select another nutrient type by using the nutrient codes from the USDA website.

The last step once you've created the above webhook is to add one more step that outputs those results to an email for you.

food-email6

As you can see, you can change the appearance of the email template. The gray fields in the email above are the embedded values from the last webhook web request.

Here's what the report email looks like when I sent a request for carbohydrate information about carrots.

food-email7

It's a fast and convenient way to get nutritional info. Zapier also has integration with Burst SMS and a few other services that would allow you to text your food request rather than use email.

Researching Economics by Location

If you're thinking about moving to a new location, like a new state, it's nice to know what the general economic health is of those communities before you decide to take the plunge.

The U.S. Department of Commerce supports the Open Data initiative by providing the ability to make a web service request to obtain location-based economic statistics. But, the API key you obtained from data.gov doesn't to work here. You have to sign up for a unique API key through BEA.gov.

Using the same approach as with the USDA example above, you can pass the "State" and the years that you want to look up, to Zapier via email. To capture this, choose the Zapier email trigger and give it a unique address starting with something like "stateeconomics". Then create a Webhooks "zap" where you can craft the web request URL required by BEA.gov.

http://bea.gov/api/data/?UserID=YOUR_KEY&method=GetData

&datasetname=RegionalIncome&TableName=CA1&LineCode=1&Year=2013,2014

&GeoFips=23000&ResultFormat=json

The trick here will be to send the email with the code for the specific U.S. state in the Subject, and the years separated by commas in the body.  Here, there's no State-to-Code lookup, so you'll need to use the state code list in the User Guide.

Next, add an action "zap" using Zapier Webhooks.  Now you're going to craft the URL web request using the parameters brought in by the email.

economics

This will run the query, and then you can add an email action event next, where the query results can go.

economics2

Here's what that final email looks like when I submitted a request for the economic data for the state of Maine.

economics3

As you can see by the outlined sections above, the data from the web request gets embedded into the email template as expected.

Look Up Population Data from Slack

Let's give email a break for a bit and instead let's look at triggering a data lookup from some other web service, like Slack.

Slack is a wonderful trigger method for something like this because it has the ability to create custom "slash commands".

slack-population-lookup2

Once you create a custom command, you can issue a POST web request to an external service, like Zapier. But before you do this, you need to tell Zapier to generate the "listener" URL link. You do this by choosing the Webhooks trigger and selecting "Catch Hook".

slack-population-lookup1

When you do this, Zapier gives you the URL you need to program your Slack "send" command. That's the URL you paste into the Slack Slash Command configuration page.

slack-population-lookup3

Save this in Slack, and then go back to Zapier and finish saving the new Webhook "catch".

For the next Zapier "action", you will choose another Zapier Webhook. You'll notice that now you can choose "GET" as an option. This will let you paste the Census Bureau web service URL to look up the state population.

http://api.census.gov/data/2014/acs1?get=NAME,B01001_001E&for=state:23&key=YOUR_KEY

Like some other government agencies, the Census Bureau won't use the same key that you obtained from other sites. You'll need to request a special Census Bureau key.

When you set up the Zapier Webhook, the "for=state" parameter will be the variable that comes in from the Slack command (see below).  But before we get to that, notice that both the report type and the state are represented in numeric code. "B01001_001E" stands for the total population.

There are actually many more statistics available. First, you can see all the state codes by pasting the following URL in your web browser (with your correct key).

http://api.census.gov/data/2014/acs1?get=NAME,B01001_001E&for=state:*&key=YOUR_KEY

This listing shows the population of all states. The last two numbers are the state codes. Those are the state codes you can use in your command.

slack-population-lookup4

The Census Bureau lists the codes for other statistics on their website as well. You have access to things like population by gender, age, whether they work from home, enrollment in school, and much more.

So, let's go back to the Zapier Webhook that is going to take the command from Slack and issue the web request to the Census Bureau. Here's what that looks like.

slack-population-lookup5

The "for" query parameter is the one that needs to receive the state code sent from the Slack command.

Once this webhook is working, the next step is to add a Slack action that sends the results back to you in Slack as a direct message.

slack-population-lookup6

That's all there is to it. So now, whenever you issue the command you created to look up the population of any U.S. State, you'll receive a direct message from Slackbot with the answer.

slack-population-lookup7

Who would have thought the Census Bureau could actually be useful?

Request NASA Satellite Image of Your Location

This last automation is probably the coolest one I've ever created. To accomplish it, I actually had to use two competing automation services -- IFTTT and Zapier.

Why? Well IFTTT has a fantastic mobile app called the "DO Button" to trigger automations. Zapier doesn't. What Zapier does better is the ability to parse more complex Webhooks and preview the results. In this example, I'm going to show you how to accomplish these steps:

  1. Use the "DO Button" app to send your geo-coordinates to a spreadsheet
  2. Zapier will retrieve them, and issue a web request to NASA for the latest satellite image at those coordinates
  3. Zapier will SMS a link of the image back to you.

It doesn't get much simpler than that. You tap a button to send your current coordinates, and you receive the image!

First, you'll want to install the DO Button from Google Play [No Longer Available]. And if you don't have an IFTTT account, you should open one now.

Once you launch the DO Button app, create a new recipe that will send your current coordinates to a spreadsheet whenever you press the button. Make sure the Google Drive account you use is the same one you've used to register the Google Sheets app on Zapier.

satellite-image5

Every time you tap the DO button, your current coordinates will get added to that spreadsheet into a new row.

Now, go into Zapier and start by creating a Zap with Google Sheets as the trigger. Have it look for any new rows in that same spreadsheet (in the example above, the sheet was named "Locations").

satellite-image6

Next, create an action where Zapier will issue the web request to NASA using your location coordinates.

satellite-image3

Next, create another action that will send the resulting satellite image link to you via SMS.

satellite-image4

So, now your automated workflow is done.

Think about how cool this is now -- all you have to do is tap your "DO Button" app; your location coordinates instantly get sent to Zapier; Zapier asks NASA for a satellite image of your current location, and then sends the URL of that image to you via SMS.

Don't you just love technology?

Other Government Data

I think that NASA's data is the most interesting, but there are also plenty of uses for data from agencies like the USDA, FDA, the Census and more.

Here are a few more useful web requests you can use to pull information from the U.S. government:

1. Look up college scorecards by college name:

http://api.data.gov/ed/collegescorecard/v1/schools?school.name=boston%20college&api_key=YOUR_KEY

2. Pull up political campaign contributions from the FEC.

a) Find the candidate ID by name:

https://api.open.fec.gov/v1/candidates/?name=SANDERS%2C%20BERNARD&api_key=YOUR_KEY

&office=P&per_page=20&page=1&sort=name&candidate_status=C

&sort_nulls_large=true

b) Query list of committees connected to the candidate:

https://api.open.fec.gov/v1/candidate/P60007168/committees/?page=1&per_page=20&sort_nulls_large=true&api_key=YOUR_KEY&sort=name

c) Use Committee ID to look up spending/contributions:

https://api.open.fec.gov/v1/committee/C00590646/totals/?page=1&sort_nulls_large=true&per_page=20&api_key=YOUR_KEY&sort=-cycle

https://api.open.fec.gov/developers/#!/financial/get_committee_committee_id_totals

3. Look up government services and programs available for minority-owned small businesses:

http://api-business.usa.gov/program/JSON?size=25&offset=5&ownership=minority&api_key=YOUR_KEY

These web requests can be automated using the same approach as the first four examples in this article. Why waste your time digging through government web pages filled with complicated charts and tables when you can just issue a web query and get that information delivered to you instantly?

Zapier and IFTTT both offer the fastest and most convenient ways to automate these "GET" web requests without having to know a thing about programming, but if you are a programmer these government web APIs are that much more powerful.

Do you see any useful ways you can make use of government data in your own life? What creative automations can you dream up for your own life? Share your thoughts and ideas in the comments section below!

Image Credit:many folders by lansvision via Shutterstock, Alexaldo via Shutterstock