A How-To Guide to the United Kingdom's Police Data API

Force Related Data

List of Forces

A list of all police forces available through the API can be accessed through the List of Forces request. Like before, we will use PHP to make our API calls and store the result in the $request variable.

$request = 'https://data.police.uk/api/forces';

We can then take the result and again use the file_get_contents() function within PHP to read the entire response into a string and then decode the JSON formatted string into an array and print that array. This call returns both a "id" and "name" attribute. This "id" attribute serves as the primary key for the following service requests as well. Let's print the name attribute to see a list of all police forces in England, Wales, and Northern Ireland.

Force Specific Information

A user may find information regarding a specific police force using the Force Specific request. The information returned from this API call includes description, URL, telephone, id, and name information of a particular police force. The request is formed as follows:

$request = 'https://data.police.uk/api/forces/metropolitan';

As you can see, the request requires the user to append a force specific "id" attribute to the end of the request URL. You may examine the information returned from using this API request regarding the Metropolitan Police Force here.

Senior Officers

One of the more interesting features of this API is the ability to retrieve substantial force specific information, including information about Senior Officers within a specific police force. Let's take a look at the senior officers of the Gloucestershire police force. First, we form our Force Senior Officers request (once again appending the force specific "id" to the end of the URL in the form of ...forces/["id"]/people) and place a call to the API as so.

$request = 'https://data.police.uk/api/forces/gloucestershire/people';

Then we need to read the response into a string and then decode the JSON formatted string.

$response = file_get_contents($request);
$JSONarray = json_decode($response, true);

Now all that is left is to print the key:value pairs of the array. We can do that with the following:

foreach ($JSONarray as $key => $value) {
echo $value["name"] . "<"br">";
echo $value["rank"] . "<"br">";
echo $value["bio"] . "<"br">";

Which results in the name, rank, and bio of the senior officers of the Gloucestershire police force. Unfortunately, this API does not contain this information for the majority of police forces, only a few have provided as many details as this particular police department. In addition to Force specific information, the API also provides access to Crime specific information as well.