How TrackMaven Digs Up Data: An Introduction to APIs & Python – TrackMaven

How TrackMaven Digs Up Data: An Introduction to APIs & Python

what is an API

For the modern marketer, data is key. The more information marketers have at their fingertips, the more effectively they can gauge the success of their strategy. Having up-to-the-minute data allows a marketer to be proactive, not reactive. A proactive marketer knows which content will drive traffic, which channels will yield the greatest return on investment, and which ad campaigns will most effectively capture qualified leads – and they have the data to prove it.

At TrackMaven, we’re all about being data-driven. We constantly strive to present current, relevant data to our users in a form that is both simple to understand and powerful to use. However, the first step is to go out and – as our mascot Maven would say – dig up the data marketers need.

Maven Digging Up Data

The TrackMaven application gathers data from a large number of different sources. Social networks, blog RSS feeds, news publications and ad campaign trackers are among the many channels that pipe data into TrackMaven to be viewed and analyzed. Though these sources differ greatly in the type of information they provide, the principle of accessing them is fundamentally the same. It can be conveniently expressed with a three-letter acronym: the API.

What Is An API?

An API, or application programming interface, is generally the ‘surface’ that a computer program presents to the outside world. It is a series of clearly defined methods to transfer information in and out of said application. While the topic of APIs is fascinating (to engineers, at least) and very broad, we can concentrate specifically on web APIs.

A web API is a series of URLs designed to return a website’s information in a computer-readable form. It is the no-frills counterpart to the highly visual, interactive experiences designed for human website users. Many large websites, and all web applications that sell data, will expose an API to allow their customers to access information in a fast, repeatable, programmatic way. This allows third-party applications to grow around a company’s set of data, creating a symbiotic relationship which benefits both consumers and producers (think Twitter clients or Facebook games).

At TrackMaven, we’ve become old hands at getting data from web APIs. While each API may vary slightly in its URL structure, authentication method, or limits to the amount and type of data that is obtainable, there are similarities that can be seen across the majority of services. Once these patterns become apparent, it becomes quicker and easier to get data from a particular source. In fact, the basics of accessing an API can be distilled into a simple enough form that only a small amount of coding knowledge is needed to access a world of data. For the data-driven marketer, having access to this sea of information could be immensely valuable… so let’s get started learning how to access an API!

Let’s Go Digging

We’ll use the CrunchBase API for our example. CrunchBase is a “free database of technology companies, people, and investors.” It contains lots of useful info around companies’ size, financing and web presence. It makes for a good example because its authentication process is very easy - many larger services require more complex signups to access their API. For now, let’s go register ourselves
with CrunchBase
and get our API key!

We enter our user details, then create an application for ‘personal use’, as shown below:

Creating a CrunchBase account

Once we’ve done this, we’ll get given our API key, which we can view at http://developer.crunchbase.com/apps/mykeys.

Now that we have this key to the door that is the CrunchBase API, we can see data from an API URL directly in our browser, just like a normal URL. We simply include the API key in our URL as a parameter. Let’s try visiting the API URL for TrackMaven on CrunchBase:

http://api.crunchbase.com/v/1/company/trackmaven.js?api_key=<my_api_key>

If we visit this URL, we get a response containing data! Woo!

TrackMaven JSON

Notice that the page doesn’t look like a standard web page. This is because the data is presented in JSON, or JavaScript Object Notation. A different format to the HTML responses we normally see from websites, JSON is a common way to present structured data, as it is clean and easy for computers to sort through.

Having this data in our browser is all well and good. From here, we can read through it and make use of the information in much the same way as we would a normal web page. However, if we want to manipulate the data, or get lots of data quickly, we are going to need to access the API using code.

Digging With Python

For this example, we are going to use the Python programming language. For more information about how to install and use Python, see this previous post. We are also going to be making use of the wonderful requests Python library.

[wpgist url=”https://gist.github.com/Jwpe/10686662″]

If we use the script above, we will see the same data we just saw in our browser, but this time in the command line! The big difference is that now we have the data in a place where we can manipulate it easily using Python. This allows us infinite possibilities for sorting, organizing and storing the data in a useful form. For example, we could make use of some of the techniques discussed in the previous tech post to get this same data for lots of different companies, or to find companies with only a certain amount of total money raised. CrunchBase comes with an excellent API explorer - playing around with it will help us discover more about the structure of their API, and work out ways to request additional information. The world is our digital oyster!

Finally…

TrackMaven’s use of APIs is a lot more complex than the example given above. There are many considerations that must be taken into account when gathering data at scale, such as rate limiting, error handling and storage. However, the basic principles outlined in the example underpin all of our data gathering. So when Maven is digging up data, behind the scenes he’s doing something that looks very similar to the above.

The good news is, you can now do the same. APIs don’t need to be a mystery for marketers who know a bit of Python.

Resources

If you liked this post, you might like 3 Reasons Marketers Should Learn to Code or Professional Growth: 3 Ways To Grow As A Developer (And A Marketer Too!).

Interested in digging up your own marketing data? Request a demo to see how TrackMaven can help you benchmark, track, and improve upon the marketing metrics that matter most.

Tweet
Share
Share
+1
Pin