The API is available at https://api.nsn.org.uk/v1/
Documentation homepage https://docs.api.nsn.org.uk/
The example below shows you how to authenticate against the API using CURL, and hit the /areas endpoint.
If you have an username and password, enter them here to populate the examples:
To authenticate against the API you must first POST your username and password in a JSON object in the body of your request to the /jwt endpoint to retrieve your JWT IdToken
.
'https://api.nsn.org.uk/v1/jwt',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"username": "{username}",
"password": "{password}"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Extract the IdToken
from the JSON response and include it as an Authorization token within the header of all subsequent requests
'https://api.nsn.org.uk/v1/jwt/areas',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer {IdToken}
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
The initial token also returns a RefreshToken
which you may use to refresh your IdToken
for 30 days. To refresh a token, PUT a request with your token in a JSON object in the body of your request to retrieve a new IdToken
.
'https://api.nsn.org.uk/v1/jwt',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS =>'{
"token": "{RefreshToken}"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Documentation homepage https://docs.api.nsn.org.uk/