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 ((-4.485635426415159 55.846927661362976, -4.484550596400167 55.84570024824655, -4.48716468221918 55.845108123285584, -4.489503470286898 55.8457079366112, -4.491476734513332 55.84458940794663, -4.49551980945678 55.84510962523058, -4.494910928936405 55.844582696873466, -4.496622631105429 55.84287617775358, -4.497830664514229 55.843031406184096, -4.501355096529864 55.84567416115738, -4.49976945009352 55.84511319209024, -4.497744791692266 55.84492963141184, -4.491397180671375 55.84609202302525, -4.491492893948374 55.84728429897416, -4.496240382931938 55.847377966046906, -4.496815279170196 55.848121291594744, -4.495720988838223 55.848745703744854, -4.49592775106005 55.84947852765524, -4.495441205690883 55.84973236223684, -4.49459014820077 55.84929894276106, -4.491361333462676 55.85052385298144, -4.488893352880393 55.8491412359511, -4.487557775966806 55.85025930200414, -4.486744926695306 55.84979038760232, -4.485567202530348 55.850362465858154, -4.489040414459946 55.85271424476646, -4.486743351099808 55.853212998077645, -4.484691839560514 55.85191710609484, -4.481924693827561 55.85111911963576, -4.484363880845861 55.84953291838372, -4.485530896221047 55.84929362484888, -4.486436934031682 55.84772038082306, -4.485635426415159 55.846927661362976))
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');