The API allows you to programatically retrieve data from any public scraper using an SQL query. It's all pretty easy.
GET https://api.morph.io/[scraper]/data.[format]?key=[api_key]&query=[sql]
Your API calls will be shown as downloads on the scraper page. Why?
To do the API query with the values above
curl "https://api.morph.io/codeforIATI/country-region-codes-scraper/data.json?key=[api_key]&query=select+%2A+from+%22swdata%22+limit+10"
To your Gemfile
add
gem 'rest-client' gem 'json'
Then run bundle install
. Use the following code snippet to get data
from the API.
# Get data from the morph.io api require 'rest-client' require 'json' # We're always asking for json because it's the easiest to deal with morph_api_url = 'https://api.morph.io/codeforIATI/country-region-codes-scraper/data.json' # Keep this key secret! morph_api_key = '[api_key]' result = RestClient.get morph_api_url, params: { key: morph_api_key, query: 'select * from "swdata" limit 10' } p JSON.parse(result)
# Get data from the morph.io api import requests # We're always asking for json because it's the easiest to deal with morph_api_url = "https://api.morph.io/codeforIATI/country-region-codes-scraper/data.json" # Keep this key secret! morph_api_key = "[api_key]" r = requests.get(morph_api_url, params={ 'key': morph_api_key, 'query': "select * from "swdata" limit 10" }) print r.json()
You'll need the requests library if you don't already have it. Install it with
pip install requests
This example uses jquery. Also, you could use this in a web browser as it requests jsonp.
var morph_api_url = 'https://api.morph.io/codeforIATI/country-region-codes-scraper/data.json'; var morph_api_params = { // Keep this key secret! key: '[api_key]', query: "select * from "swdata" limit 10" }; $.ajax({ url: morph_api_url + '?' + $.param(morph_api_params), dataType: 'jsonp', success: function(data) { console.log('received data: ' + JSON.stringify(data)); } });
Use the following code snippet to get data from the API.
<?php $morph_api_url = "https://api.morph.io/codeforIATI/country-region-codes-scraper/data.json"; $morph_api_key = "[api_key]"; $query = "select * from "swdata" limit 10"; $response = file_get_contents($morph_api_url.'?key='.$morph_api_key.'&query='.urlencode($query)); $js = json_decode($response,true); print_r($js); ?>