NSN API Documentation (v1.0)

The API is available at https://api.nsn.org.uk/v1/

Documentation homepage https://docs.api.nsn.org.uk/


CURL example

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:

POST /v1/jwt

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.

var https = require('https);

var options = {
  'method': 'POST',
  'hostname': 'api.nsn.org.uk',
  'path': '/v1/jwt',
  'headers': {
    'Content-Type': 'text/plain'
  }
};

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

var postData =  "{\"username\": \"{username}\", \"password\": \"{password}\"}";

req.write(postData);

req.end();

GET /v1/jwt/areas

Extract the IdToken from the JSON response and include it as an Authorization token within the header of all subsequent requests

var https = require('https);

var options = {
  'method': 'GET',
  'hostname': 'api.nsn.org.uk',
  'path': '/v1/jwt/areas',
  'headers': {
    'Authorization': '{IdToken}'
  }
};

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

req.end();

PUT /v1/jwt/

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.

var https = require('https);

var options = {
  'method': 'PUT',
  'hostname': 'api.nsn.org.uk',
  'path': '/v1/jwt',
  'headers': {
    'Content-Type': 'text/plain'
  }
};

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

var postData =  "{\"token\": \"{refreshToken}\"}";

req.write(postData);

req.end();

Documentation homepage https://docs.api.nsn.org.uk/