Address Auto-Complete - API Help

Address Auto-Complete - API Help

Hi There,

I'm trying to create an address autocomplete using an address API, I've gotten so far from pulling from other online sources but have come across an issue I'm not sure how to tackle. I'm not a dev firstly so just trying to piece things together bit by bit.

I have an input field in a form that when a value is entered it runs a function which lookups the postcode via a API and then returns a list of possible addresses for the user to select, my issue is that the return of the API is the address in one string format i.e not broken down.. The return of the API also returns a ID number for the address that then can be called from the API(different endpoint) to return the address in its broken down items i.e line1, line2, city, etc. How can I hold the ID number until the user has selected the address from the dropdown and then call that ID number for it to return the address in full so I can then match it into the correct parts of the proper 'Address' field.

Hope this makes sense! Happy for any suggestions on how this could be done in a more efficient way as well! As I say I'm not a dev but know a little and probably enough to be dangerous!

Code of the function;
list addressOptions(string postcodeString)
{
// Do API call for addresses
response = invokeurl
[
url :url
type :GET
];
info response;
// Convert the JSON response to a map
responseMap = response.toMap();
// Extract the 'records' list from the response map
recordsList = responseMap.get("records");
// Initialize the output list
outputList = list();
// Iterate over each record and extract the 'l' elements (addresses)
for each  record in recordsList
{
addressLine = record.get("l");
// Append the address line with '|'
addressLineWithPipe = addressLine + " |";
outputList.add(addressLineWithPipe);
}
// Return the output list
return outputList;
}


Code for the workflow as the postcode is entered for the function and it's return;

//
//
//Search for Addresses (Using Standalone Function)
addressList = thisapp.addressOptions(input.Address_Search_Input).toList("|, ");
addressList = addressList.toList("|,");
//
//
//Populate Addresses
input.Address_Select_Dropdown:ui.append(addressList);
//
//
//Show Address Dropdown
show Address_Select_Dropdown;



Any help would be greatly appreciated! 

Thanks!