This page provides example queries that you can adapt and use with OS Places API. The examples use Node.js the popular axios module.
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();
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();
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();
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();
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();
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();