Visualizing Crunchbase Part 2

15th July, 2014

image03

In April we looked at how easy it was to visualize a CrunchBase network in KeyLines, especially with the new Neo4j backend.

A few days ago CrunchBase announced the release of v2.0 of their API, so we thought we’d bring you up to speed on how it affects the code in our original article.

What’s changed in CrunchBase 2.0?

The updated API has changed in three main ways:

  1. API calls relate more specifically to each of the Crunchbase data objects, so you can make calls to return specific collections (Organizations, People, Products) or individual items
  2. The data is returned in a better structure
  3. There is better support for pagination for data collections.

How to make a specific request with CrunchBase API 2.0

To return a specific data item using the old API, for example Facebook, your Request URI would have looked like this:

http://api.crunchbase.com/v/1/company/facebook.js?api_key={your api key}

With the new API, the request now becomes:

http://api.crunchbase.com/v/2/organization/facebook?api_key={your api key}

And here’s the code to create our requests and get our JSON objects out:

function getOrganizationUrl(permalink) {
return 'http://api.crunchbase.com/v/2/'
     +  'organization/'
     +  encodeURIComponent(permalink)
     +  '?user_key='
     +  apikey;
   }

How to parse the response

Now we have our JSON object, we need to parse it to construct nodes and links. We’ll do this by walking through the new response data structure, which has changed significantly.

For individual object requests, the response now has a properties object and a relationships object.
Crunch-base-API

With each of the relationships (acquisitions, competitors, funding_rounds, investments) there’s an items collection and a paging object, meaning we can choose to display just the first page or results, or use the paging objects to fetch them all in one go.

Here’s an example of just picking out the competitors. Each competitor company is represented by a node, with a link back to the main company:

function parseResponse(data){
     // Get the main company's name and permalink
     var mainCompanyId   = data.properties.permalink;
     var mainCompanyName = data.properties.name;

     // Add the main company node to the chart
     addNode('company', mainCompanyId, mainCompanyName, '#B9121B');

     // Parse competitors
     if(data.relationships.competitors)
     {
        var competitors = data.relationships.competitors;

        for (var i = 0; i < competitors.items.length; i++)
        {
           var competitorId   = competitors.items[i].path.split("/")[1];
           var competitorName = competitors.items[i].name;

           // Add the competitor company node
           addNode('company', competitorId, competitorName, '#B9121B');

           // Now add a link from our main company to the competitor
           addLink('company', mainCompanyId, 'company', competitorId, 'Competitor', '#4C1B1B', false);
       }
     }
     // Todo: Parse founders 
     // Todo: Parse acquisitions
     // Todo: Parse funding_rounds
     // Todo: Parse investments
   }

We’ve made use of two helper functions (addNode and addLink) to add node and link information to an array of chart items (‘myChartItems’). Then we just need to send the newly created items to the chart object, along with some instructions for the layout:

myChart.expand(myChartItems, {fit: true, animate: true, tidy: true});

And we’re done!

Crunchbase-visualization-basic-2

So, although the CrunchBase API has changed significantly, with only a few minor tweaks to the code from our original article, we are still able to get the same visualization results.

Subscribe to our newsletter

Get occasional data visualization updates, stories and best practice tips by email