Use AidData's API

AidData's API

The AidData API allows for programmatic access to the catalogue of AidData information. If you have any questions or suggestions for improving the API documentation please contact us at data@aiddata.org or on our #aiddata Freenode channel.

Before getting started we suggest reading:

Sandbox Rules

Terms and Conditions

The AidData API consists of four main namespaces:

API 
Datadata such as sector codes and donors to be used as parameters in Flows, Aid, and GIS.
Flowsfinancial flows including aid, foreign direct investment, and remittances.
Aiddata on exclusively aid funding.
GISretrieve AidData maps and layers.
Parameter Quick GuideAll of the parameters that the different APIs accept.

 

The API can be accessed via either GET or POST requests and responds with json.

 

API Samples

Find the id for recipient Malawi

 
// Call http://api.aiddata.org/data/destination/organizations?term=Malawi
$.ajax({
    type: 'GET',
    url:  'http://api.aiddata.org/data/destination/organizations',
    data: {term:'Malawi'},
    success:function(response){
      console.log(response);
      console.log("Malawi's id: " + response.hits[0].id);
    }
  });


 

Filter to projects from all sources from 2005-2010, where Malawi is the recipient

  //Filter to projects from all sources from 2005-2010, where Malawi is the recipient
  var malawiFilters = {
    src:'1,2,3,4,5,6,7,3249668',        // Use all sources
    ro:110593668,                       // Recipient Org is Malawi
    y:'2005,2006,2007,2008,2009,2010',  // Years 2005-2010
    t:1,                                // Transaction type Commitments
    from:0,                             // Result position to start at
    size:50                             // Number of results to return
  };

  $.ajax({
    type: 'GET',
    url:  'http://api.aiddata.org/aid/project',
    data: malawiFilters,
    success:function(response){
      console.log(response);
    }
  });

 

Retreiving more than 50 projects


  // The API returns a max of 50 results for certain queries.
  // Using the 'from' and 'size' params you can iterate to return more results.
  // This example will get 200 projects for a given query.
  var pagesReturned = 0;    // Number of pages returned so far.
  var allProjects = [];     // Array of projects returned.
  var resultsPerPage = 50;  // Number of projects per a page
  var targetNumOfPages = 4; // This will yield us 200 projects. (4 pages of 50 projects each)
  var malawiFilters = {
    src: '1,2,3,4,5,6,7,3249668',        // Use all sources
    ro: 110593668,                       // Recipient Org is Malawi
    y: '2005,2006,2007,2008,2009,2010',  // Years 2005-2010
    t: 1,                                // Transaction type comittments.
    size: resultsPerPage
  };

  // Loop through targetNumOfPages making requests to the api.
  for(var currentPage = 0; currentPage < targetNumOfPages; currentPage++){

    // Update the filter to start from the last project we got.
    malawiFilters.from = (currentPage * resultsPerPage);

    $.ajax({
      type: 'GET',
      async: true,
      url:  'http://api.aiddata.org/aid/project',
      data: malawiFilters,
      success: function(response){

        // Print response for debugging.
        console.log(response);

        // Merge latest results into out array
        allProjects = allProjects.concat(response.items);

        // Check if we have all requests returned
        pagesReturned++;
        if(pagesReturned == targetNumOfPages){
          console.log('The first 200 projects that match our filters:');
          console.log(allProjects);
        }
      }
    });
  }


console.log('The first 200 projects that match our filters:');
console.log(allProjects);