add cart choropleth column cross cube error file folder geo help home lock obs poi rdf remove search slice spreadsheet success table unlock warning

[this is a icon-] developer tool

SPARQL 1.1 Query: Results

Edit query
Query results
s p_blank o_blank geosparql: Geometry geosparql: asWKT POLYGON ((-3.1817495879258173 55.90554940919724, -3.184243670860788 55.91054655640159, -3.2084455141576673 55.912511071437336, -3.2205792911919335 55.91160600823019, -3.2220622250557414 55.913485452748915, -3.244913816984634 55.91283784187561, -3.255252282183612 55.913977392356834, -3.2542128347176638 55.919889743520955, -3.248035539385685 55.922908723377205, -3.252598249837841 55.92569465380208, -3.2586681301077185 55.92548095606459, -3.251666700045251 55.93323493887998, -3.2459824939379525 55.9335334062602, -3.2372884244250377 55.936782159177085, -3.23601834236913 55.93289342205758, -3.216378923157635 55.94261311500692, -3.207714347823148 55.93674052283111, -3.1951333740334444 55.939555327250055, -3.182754400654566 55.9404942300396, -3.1805091621643204 55.936945870762436, -3.167811175399898 55.94024595706775, -3.1441730932771823 55.93652044707046, -3.141214465585398 55.93259076175897, -3.1472553545275845 55.93118137174162, -3.1442840281417186 55.92518788051259, -3.148496415672831 55.922599505544554, -3.140094092167152 55.92022453196972, -3.152390898193477 55.912607193852615, -3.163307498633735 55.91236261298394, -3.168644012321219 55.90920668197888, -3.1817495879258173 55.90554940919724))
SPARQL API: The Basics

The most flexible way to access the data is by using SPARQL, a query language, analagous to SQL for relational databases, for retrieving and manipulating data from graph databases like ours. We support SPARQL 1.1 query syntax. Many online tutorials are available.

To submit a SPARQL query from your code, you issue an HTTP GET or POST to our endpoint:, with the query itself as a url-encoded parameter called query.

For example, to run the following simple SPARQL query and get the results as JSON:

SELECT * WHERE {?s ?p ?o} LIMIT 10

Option 1: POST (recommended)

Issue a POST to the endpoint, with the query in the body, and an Accept header of sparql-results+json:

Accept: application/sparql-results+json
Content-Type: application/x-www-form-urlencoded


Option 2: GET

Issue a GET to the following URL (note the .json extension - see the formats section for more detail on this):


Scroll down to the end of this page for examples of both of these methods in a few different languages.

Results formats

As with other aspects of our API, to get the data in different formats, you can use either (a) a format extension or (b) an HTTP Accept header. Available result formats depend on the type of SPARQL query. There are four main forms:

SELECT queries return tabular results, and the formats available reflect this:

Format Extensions Accept Headers
XML .xml application/xml,
JSON .json application/json,
Text .txt, .text text/plain
CSV .csv text/csv

CONSTRUCT and DESCRIBE queries return graph data, so the results are available in the same formats as our resource APIs:

Format Extensions Accept Headers
RDF/XML .rdf application/rdf+xml
N-triples .nt, .txt, .text application/n-triples,
Turtle .ttl text/turtle
JSON-LD .json application/ld+json,

ASK queries return a boolean result:

Format Extensions Accept Headers
XML .xml application/xml,
JSON .json application/json,
Text .txt, .text text/plain
Results pagination

We accept page and per_page parameters for paginating the results of SELECT queries (we automatically modify your query to apply LIMIT and OFFSET clauses). For other query types (i.e. DESCRIBE, CONSTRUCT, ASK), pagination like this doesn’t make so much sense, so these parameters are ignored.

For requests made through the website (i.e. HTML format), the page size is defaulted to 20. For requests to our sparql endpoint for data formats (i.e. non-HTML), there will be no defaults for these parameters (i.e. results are unlimited. For performance reasons we generally advise LIMITing your query if possible).

Parameter Substitution

You can parameterise your SPARQL by including %{tokens} in your queries, and providing values for the tokens in the request parameters.

Note that the following tokens are reserved and cannot be used as parameters for substitution:

  • controller
  • action
  • page
  • per_page
  • id
  • commit
  • utf8
  • query
Cross Origin Resource Sharing

Our servers are configured to allow access from all domains. This means that if you’re writing JavaScript to request data from our server in to a web page hosted on another domain, your browser should check this header and allow it.

If you need to support very old browsers, you can additionally pass a callback parameter and the results will be wrapped in that function. For example:

This help topic on the jQuery website has more details.


Using cURL

Here’s a couple of examples running a query using the widely available cURL command line program.

Request the results as XML, using a POST:

curl -X POST -H "Accept: application/sparql-results+xml" -d "query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010"

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json"*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010

Using JavaScript

This example HTML page uses jQuery to issue a POST to our SPARQL endpoint, requesting the results as JSON.

<!DOCTYPE html>
	<script src=''></script>
<script type='text/javascript'>

	var query = 'SELECT * WHERE {?s ?p ?o} LIMIT 10';
	var url = '';
		method: 'POST',
		dataType: 'json',
		url: url,
		data: {query: query},
		success: function(data) {
			alert('success: ' + data.results.bindings.length + ' results');