Getting started with example queries using Node.js
This page provides example queries that you can adapt and use with OS Places API. The examples use Node.js the popular axios module.
What you need
OS Places API added to an API project in the OS Data Hub with an API Key. See Getting started with an API project for more information.
A text editor like Visual Studio Code
Running a Find query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function find() {
axios.get('https://api.os.uk/search/places/v1/find?maxresults=1&query=Ordnance%20Survey,%20Adanac%20Drive,%20SO16&key=' + apiKey)
.then(function(response) {
var response = JSON.stringify(response.data, null, 2);
console.log(response);
});
}
find();
Running a Postcode query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function postcode() {
axios.get('https://api.os.uk/search/places/v1/postcode?postcode=SO16&key=' + apiKey)
.then(function(response) {
var response = JSON.stringify(response.data, null, 2);
console.log(response);
});
}
postcode();
Running a UPRN query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function uprn() {
axios.get('https://api.os.uk/search/places/v1/uprn?uprn=200010019924&key=' + apiKey)
.then(function(response) {
var response = JSON.stringify(response.data, null, 2);
console.log(response);
});
}
uprn();
Running a Nearest query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function nearest() {
axios.get('https://api.os.uk/search/places/v1/nearest?point=437293,115515&key=' + apiKey)
.then(function(response) {
var response = JSON.stringify(response.data, null, 2);
console.log(response);
});
}
nearest();
Running a Bounding Box query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function bbox() {
axios.get('https://api.os.uk/search/places/v1/bbox?bbox=437201,115447,437385,115640&key=' + apiKey)
.then(function(response) {
var response = JSON.stringify(response.data, null, 2);
console.log(response);
});
}
bbox();
Running a Radius query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
async function radius() {
axios.get('https://api.os.uk/search/places/v1/radius?point=437293,115515&radius=100&key=' + apiKey)
.then(function(response) {
var response = JSON.stringify(response.data, null, 2);
console.log(response);
});
}
radius();
Running a Polygon query
const axios = require('axios');
const apiKey = 'INSERT_YOUR_API_KEY_HERE';
function polygon() {
axios.post('https://api.os.uk/search/places/v1/polygon/?key=' + apiKey, {
"type" : "Polygon",
"crs" : {
"type" : "name",
"properties" : {
"name" : "urn:ogc:def:crs:EPSG::27700"
}
},
"coordinates": [[[437226,115652],[437212,115495],[437387,115495],[437368,115663],[437226,115652]]]
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
};
polygon();
Last updated
Was this helpful?