Documentation


How to use the API

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?

Parameters

The full name of the scraper as seen in the url
The SQL query to perform on the scraper data. Ensure it is url encoded.
Format of outputted data
(Optional) To return JSONP set "callback" to the name of your javascript callback function.

A note on atom feeds

If you are returning an atom feed, you must configure your SQL query to return a title, content, link and date.

To make it easier, you can specify mappings below, and this will update your query above. You can link fields together with the double pipe (||) operator.

Example

To do the API query with the values above

curl "https://api.morph.io/Jbsh1999/kik/data.json?key=[api_key]&query=select+%2A+from+%22data%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/Jbsh1999/kik/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 "data" 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/Jbsh1999/kik/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 "data" 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/Jbsh1999/kik/data.json';
var morph_api_params = {
  // Keep this key secret!
  key: '[api_key]',
  query: "select * from "data" 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/Jbsh1999/kik/data.json";
$morph_api_key = "[api_key]";

$query = "select * from "data" limit 10";

$response = file_get_contents($morph_api_url.'?key='.$morph_api_key.'&query='.urlencode($query));
$js = json_decode($response,true);

print_r($js);
?>