I am using a postcode lookup API to retrieve addresses for a postcode provided by the user. Response example:
{
"postcode": "N1 2AB",
"latitude": 51.54189,
"longitude": -0.09913820000000001,
"addresses": [
{
"formatted_address": [
"1 Braes Street",
"",
"",
"London",
""
],
"thoroughfare": "Braes Street",
"building_name": "",
"sub_building_name": "",
"sub_building_number": "",
"building_number": "1",
"line_1": "1 Braes Street",
"line_2": "",
"line_3": "",
"line_4": "",
"locality": "",
"town_or_city": "London",
"county": "",
"district": "Islington",
"country": "England"
},
{
"formatted_address": [
"2 Braes Street",
"",
"",
"London",
""
],
"thoroughfare": "Braes Street",
"building_name": "",
"sub_building_name": "",
"sub_building_number": "",
"building_number": "2",
"line_1": "2 Braes Street",
"line_2": "",
"line_3": "",
"line_4": "",
"locality": "",
"town_or_city": "London",
"county": "",
"district": "Islington",
"country": "England"
}
]
}
I have written the following function which calls the API:
// Filename: backend/getaddressio.jsw
import {fetch} from ‘wix-fetch’;
export function getAddresses(postcode) {
const url = ‘https://api.getaddress.io/find/’;
const key = ‘XXXXXXXXXXXXXXXXXX’;
let fullUrl = url + postcode + ‘?api-key=’ + key + ‘&expand=true’;
return fetch(fullUrl, {method: ‘get’})
.then(response => response.json())
.then(json => json.addresses.building_name);
}
…and subsequently am calling the function upon my page loading:
import {getAddresses} from ‘backend/getaddressio’;
import {session} from ‘wix-storage’;
let sessionpostcode = session.getItem(“sessionpostcode”);
$w.onReady(function () {
getAddresses(sessionpostcode)
.then(what do I enter here to control options for #dropdown1?);
});
What do I enter in the two green-marked sections above so that I can update the options of the dropdown with all of the values for building_name in the JSON response?