Hello, I want consume a External API to auto complete customer address on Business Central , I would like to know what is the best option to do this . APi is https://getaddress.io/Documentation .
Hello, I want consume a External API to auto complete customer address on Business Central , I would like to know what is the best option to do this . APi is https://getaddress.io/Documentation .
codeunit 50100 "GetAddressIntegration"
{
procedure GetAddressFromPostcode(Postcode: Text; var Customer: Record Customer)
var
HttpClient: HttpClient;
HttpResponse: HttpResponseMessage;
ResponseText: Text;
JsonObj: JsonObject;
JsonToken: JsonToken;
AddressesArray: JsonArray;
Url: Text;
ApiKey: Text;
begin
ApiKey := 'YOUR_API_KEY'; // Store securely in a setup table or key vault
Url := 'https://api.getAddress.io/find/' + Postcode + '?api-key=' + ApiKey;
if not HttpClient.Get(Url, HttpResponse) then
Error('Failed to connect to getAddress.io API.');
if not HttpResponse.IsSuccessStatusCode then
Error('API Error: %1', HttpResponse.HttpStatusCode);
HttpResponse.Content.ReadAs(ResponseText);
JsonObj.ReadFrom(ResponseText);
// Extract first address for simplicity (you could add a selection UI)
if JsonObj.Get('addresses', JsonToken) then begin
AddressesArray := JsonToken.AsArray();
if AddressesArray.Get(0, JsonToken) then begin
SplitAddress(JsonToken.AsValue().AsText(), Customer);
end;
end else
Message('No addresses found for postcode %1.', Postcode);
end;
local procedure SplitAddress(AddressText: Text; var Customer: Record Customer)
var
Parts: List of [Text];
begin
// Address comes as a single string, e.g., "10 Downing Street, London, SW1A 2AA"
Parts := AddressText.Split(', ');
if Parts.Count >= 1 then Customer.Address := CopyStr(Parts.Get(1), 1, MaxStrLen(Customer.Address));
if Parts.Count >= 2 then Customer.City := CopyStr(Parts.Get(2), 1, MaxStrLen(Customer.City));
if Parts.Count >= 3 then Customer."Post Code" := CopyStr(Parts.Get(3), 1, MaxStrLen(Customer."Post Code"));
// County isn’t always explicit; you could extend logic or use API’s formatted_address
end;
}
Hello,
We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.
dynamicsuser.net/.../developers
I will open this up to the community in case they have something to add.
Thanks.
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,409
Most Valuable Professional
nmaenpaa
101,156