I have modified the demo page I received with PI version 2 as follows:
Note this works for Me and also for Dave but does not work for Gary Wann.
async function fetchPostcodeData(postcode) {	
	const town   = document.querySelector("[name=town]");
	const ward   = document.querySelector("[name=ward]");
	const county = document.querySelector("[name=county]");
	const region = document.querySelector("[name=region]");
	const longitude = document.querySelector("[name=longitude]");
	const latitude = document.querySelector("[name=latitude]");
	const country = document.querySelector("[name=country]");
	if (postcode.length < 5) {
		town.value   = "";
		ward.value   = "";
		county.value = "";
		region.value = "";
		longitude.value = "";
		latitude.value = "";
		country.value = "";
		return;
	}
	const url = `https://api.postcodes.io/postcodes/${postcode}`; // URL for the API
	const data = await Pi.fetchJSON(url);
	town.value   = data.result.admin_district ?? "";
	ward.value   = data.result.admin_ward ?? "";
	county.value = data.result.pfa ?? "";
	region.value = data.result.region ?? "";
	country.value = data.result.country ?? "";
	longitude.value = data.result.longitude ?? "";
	latitude.value = data.result.latitude ?? "";
}