{# Displays information about accessing a resource via the API. datastore_root_url - The root API url. resource_id - The resource id embedded - If true will not include the "modal" classes on the snippet. Example {% snippet 'ajax_snippets/api_info.html', datastore_root_url=datastore_root_url, resource_id=resource_id, embedded=true %} #} {% set sql_example_url = datastore_root_url + '/datastore_search_sql?sql=SELECT * from "' + resource_id + '" WHERE title LIKE \'jones\'' %}

{{ _('Access resource data via a web API with powerful query support') }}. {% set api_url = 'http://docs.ckan.org/en/{0}/datastore.html'.format(g.ckan_doc_version) %} {% trans %} Further information in the main CKAN Data API and DataStore documentation.

{% endtrans %}

{{ _('The Data API can be accessed via the following actions of the CKAN action API.') }}

{{ _('Create') }} {{ datastore_root_url }}/datastore_create
{{ _('Update / Insert') }} {{ datastore_root_url }}/datastore_upsert
{{ _('Query') }} {{ datastore_root_url }}/datastore_search
{{ _('Query (via SQL)') }} {{ datastore_root_url }}/datastore_search_sql
{{ _('Query example (first 5 results)') }}

{{ datastore_root_url }}/datastore_search?resource_id={{resource_id}}&limit=5

{{ _('Query example (results containing \'jones\')') }}

{{ datastore_root_url }}/datastore_search?resource_id={{resource_id}}&q=jones

{{ _('Query example (via SQL statement)') }}

{{sql_example_url}}

{{ _('A simple ajax (JSONP) request to the data API using jQuery.') }}

  var data = {
    resource_id: '{{resource_id}}', // the resource id
    limit: 5, // get 5 results
    q: 'jones' // query for 'jones'
  };
  $.ajax({
    url: '{{ datastore_root_url }}/datastore_search',
    data: data,
    dataType: 'jsonp',
    success: function(data) {
      alert('Total results found: ' + data.result.total)
    }
  });
import urllib
url = '{{ datastore_root_url }}/datastore_search?limit=5&q=title:jones'
fileobj = urllib.urlopen(url)
print fileobj.read()