Web services allow you to expose Business Central data and operations to external systems. AL supports both SOAP and OData web services.
Example:
codeunit 50100 CustomerWebService
{
[ServiceEnabled]
procedure GetCustomer(var Customer: Record Customer)
begin
// Code to fetch customer data
end;
}
AL can interact with external APIs using HTTP requests. This allows seamless integration with other applications and services.
Example:
procedure CallExternalAPI()
var
HttpClient: HttpClient;
HttpResponseMessage: HttpResponseMessage;
JsonResponse: Text;
begin
HttpClient.Get('https://api.example.com/data', HttpResponseMessage);
if HttpResponseMessage.IsSuccessStatusCode then begin
HttpResponseMessage.Content.ReadAs(JsonResponse);
Message('Response: %1', JsonResponse);
end else
Error('Failed to call API');
end;
Data exchange features in Business Central include XMLports and Data Exchange Definitions, enabling import/export of data in various formats.
Example:
xmlport 50100 CustomerImport
{
Schema
{
// Define XML schema for import
}
trigger OnAfterInsertRecord()
begin
// Code to process imported data
end;
}