{# Displays information about accessing a resource via the API. resource_id - The resource id embedded - If true will not include the "modal" classes on the snippet. Example {% snippet 'ajax_snippets/api_info.html', resource_id=resource_id, embedded=true %} #} {% set resource_id = h.sanitize_id(resource_id) %} {% set sql_example_url = h.url_for('api.action', ver=3, logic_function='datastore_search_sql', qualified=True) + '?sql=SELECT * from "' + resource_id + '" WHERE title LIKE \'jones\'' %} {# not urlencoding the sql because its clearer #}
{{ _('Access resource data via a web API with powerful query support') }}. {% 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') }} | {{ h.url_for('api.action', ver=3, logic_function='datastore_create', qualified=True) }} |
---|---|
{{ _('Update / Insert') }} | {{ h.url_for('api.action', ver=3, logic_function='datastore_upsert', qualified=True) }} |
{{ _('Query') }} | {{ h.url_for('api.action', ver=3, logic_function='datastore_search', qualified=True) }} |
{{ _('Query (via SQL)') }} | {{ h.url_for('api.action', ver=3, logic_function='datastore_search_sql', qualified=True) }} |
{{ _('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: '{{ h.url_for('api.action', ver=3, logic_function='datastore_search', qualified=True) }}', data: data, dataType: 'jsonp', success: function(data) { alert('Total results found: ' + data.result.total) } });
import urllib.request url = '{{ h.url_for('api.action', qualified=True, ver=3, logic_function='datastore_search', resource_id=resource_id, limit=5) + '&q=title:jones' }}' {# not urlencoding the ":" because its clearer #} fileobj = urllib.request.urlopen(url) print(fileobj.read())