showapicalls.js - bennettoxford/openprescribing GitHub Wiki

This script will show all API calls made by the browser when displaying a page. It requires PhantomJS.

Usage:

$ phantomjs show-api-calls.js 'https://openprescribing.net/analyse/#org=practice&orgIds=L84613&numIds=0703021Q0BB&denom=total_list_size&selectedTab=summary'
https://openprescribing.net/api/1.0/org_code/?format=json&exact=true&q=L84613,
https://openprescribing.net/api/1.0/bnf_code/?format=json&exact=true&q=0703021Q0BB,
https://openprescribing.net/api/1.0/spending_by_practice/?format=json&code=0703021Q0BB&org=11M
https://openprescribing.net/api/1.0/org_details/?format=json&org_type=practice&keys=total_list_size&org=11M
https://openprescribing.net/api/1.0/org_location/?format=json&org_type=practice&q=11M,
var page = require('webpage').create();
var system = require('system');

var args = system.args;

if (args.length != 2) {
  console.log('Usage: phantomjs show-api-calls.js URL');
}

var url = args[1];

page.onResourceRequested = function(request) {
  if (request['url'].indexOf('openprescribing.net/api') != -1) {
    console.log(request['url']);
  }
};

page.onCallback = function(data){
  if (data.type === "exit") {
    phantom.exit();
  }
};

page.open(url, function(status) {
  page.evaluate(function(){
    setTimeout(function(){
      window.callPhantom({type: "exit"});
    }, 3000);
  });
});