Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Consume External API on Business central

(2) ShareShare
ReportReport
Posted on by 24

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 .

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,317 Moderator on at
    Consume External API on Business central
    Yes you can use the most effective way to integrate this in Business Central is by using AL code to consume the API and pairing it with a custom page control (via a page extension) to trigger the lookup.
     
    See the following example if help:
    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;
    }
     
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 8,877 Super User 2025 Season 1 on at
  • Suggested answer
    Saurav.Dhyani Profile Picture
    Saurav.Dhyani 14,302 Super User 2025 Season 1 on at
    Consume External API on Business central
    Hi,
     
     
    This playlist is not complete but example that you are looking for is ready.
     
  • CU20021523-0 Profile Picture
    CU20021523-0 8 on at
    Consume External API on Business central
    A very old thread, but did you end up getting it working?
     
    I have been testing multiple endpoint URLs and haven't gotten it to work yet. The default "https://api.getAddress.io/find/" endpoint with the API key entered does not seem to return any results when using valid postcodes.
     
    Cheers
  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Consume External API on Business central

    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.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans