Camden Open Data API


All of the tabular data sets in Camden's Open Data portal can be accessed via SODA (Socrata Open Data API). This is a basic tutorial on what's needed to access and get data from the API.
This tutorial uses an extract of the OS Open Names data set for Camden and surrounding boroughs; click here to see this in Camden's Open Data platform.

API Endpoint

The first thing you will need is the data set's API endpoint - with a data set open click the Export button, the endpoint can be copied and pasted from the API Endpoint box.
Clicking the API Docs button will open a new webpage with dynamic API documentation for that data set - this is very useful for exploring the data.
Data can be downloaded in JSON or CSV, this is set in the Endpoint URL:

API Endpoint


Hitting the API endpoint as is will return the first 1000 records from the data set (see below), using SoQL you can perform SQL-like querying on the data set. This ranges from simple select / where queries to more complex aggregation or spatial queries. Documentation on basic querying can be viewed here and a full list of SoQL functions can be viewed here.
By default API responses are limited to 1000 rows of data; this can be increased or decreased using the $limit= parameter; for example $limit=100000 will return up to 100,000 rows.
If a bad API call is made a message will be returned with some help on how to fix it, if the call is good but there are no results then an empty object will be returned.
The API field name is the same as the data set field name, but is all lowercase with underscores replacing spaces.
You can check an API field name by hovering over the information icon in the field header.

Python Examples

Below are three examples of how to use the API and SoQL in Python.
They require two Python modules, json and urlib2 which already exist in the standard Python install.
They are written in Python2 but will also work in Python3 with some changes to urlib.
Python Logo

Percent Encoding

Depending on your application you may need to percent encode your API call (the Python examples below demonstrate this); these are the most common replacements:
  • space ( ) = %20
  • apostrophe (') = %27
  • percent (%) = %25

SoQL Select/Where Query

This example demonstrates how to select particular columns and filter using a where statement. Certain columns in the data set are returned where the name_1 column  = ‘NW1 1BD’:

SoQL Select/Like Query

This example demonstrates how to do a like query. Certain columns in the data set are returned where values in the name_1 column are like ‘NW1 1B%’:

SoQL Within Circle

This example demonstrates how data can be queried spatially and return data within n metres of a given point. Using the Latitude and Longitude of NW1 1BD from the first example, this query returns all the records within 100 metres of this location and loops through the results: