Ava API Client

Feature

AL HttpClient code generator for Business Central

Updated 21 November 2026

Getting an API call to work in a client is the easy half. Rewriting it in AL, with the right headers on the right object, the body encoded, the token acquired and the secret kept out of plain text, is where the afternoon goes. Ava writes that code from the request you just sent.

From a working request to a procedure

Send the request until it returns what you want. Then press Code and choose AL. Ava generates a procedure that makes the same call: the URL with its query parameters, the method, every enabled header, the body with its content type, and the authentication you configured. Copy it into a codeunit in your extension.

This is what a POST that creates a customer with OAuth2 client credentials looks like:

procedure CreateCustomer(var ResponseText: Text): Boolean
var
    Client: HttpClient;
    RequestMessage: HttpRequestMessage;
    ResponseMessage: HttpResponseMessage;
    Headers: HttpHeaders;
    Content: HttpContent;
    ContentHeaders: HttpHeaders;
    RequestBody: Text;
    AccessToken: SecretText;
begin
    RequestMessage.SetRequestUri('https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/sandbox/api/v2.0/companies(<company-id>)/customers');
    RequestMessage.Method := 'POST';

    RequestMessage.GetHeaders(Headers);

    if not AcquireAccessToken(AccessToken) then
        Error('Failed to acquire access token.');
    Headers.Add('Authorization', SecretStrSubstNo('Bearer %1', AccessToken));

    RequestBody := '{"displayName":"Adatum Corporation","type":"Company"}';
    Content.WriteFrom(RequestBody);
    Content.GetHeaders(ContentHeaders);
    ContentHeaders.Remove('Content-Type');
    ContentHeaders.Add('Content-Type', 'application/json');
    RequestMessage.Content := Content;

    if not Client.Send(RequestMessage, ResponseMessage) then
        exit(false);

    ResponseMessage.Content.ReadAs(ResponseText);
    exit(ResponseMessage.IsSuccessStatusCode());
end;

A second procedure, AcquireAccessToken(var AccessToken: SecretText): Boolean, posts the client credentials to the Microsoft Entra token endpoint, reads access_token from the JSON answer into a SecretText, and returns false if anything went wrong. The main procedure calls it before adding the Authorization header.

The details it gets right

Every authentication type

Auth in AvaGenerated AL
Bearer tokenAn Authorization: Bearer header.
BasicCodeunit Base64 Convert encodes the user and password into an Authorization: Basic header.
API keyThe key as a header, or appended to the URL as a query parameter, whichever you chose.
OAuth2 client credentialsAn AcquireAccessToken procedure that posts to the token endpoint and returns a SecretText.
OAuth2 authorization codeA token procedure built on Business Central's own OAuth2 codeunit, calling AcquireTokenByAuthorizationCode with your client ID, authority, redirect URI and scopes. It prompts the user to sign in, as this flow must.
OAuth2 passwordA token procedure posting the username and password grant.

The secret you entered in Ava is written into the code only when you generate it, from the server where it is encrypted. The browser never has it, so the code is generated server-side rather than from the masked value the browser shows.

Bodies

JSON, raw text, XML and form-encoded bodies are written as a Text and sent with the matching Content-Type. GraphQL queries are wrapped in the JSON envelope the server expects. For a file upload the generated code leaves a marked place to load the content from an InStream, because AL has no sensible way to embed a binary in source.

cURL as well

The same button produces a cURL command, with quoting that survives a POSIX shell, for a ticket, a script or a colleague who does not use Ava. Form-data and binary bodies are included, so the command sends what Ava sent.

What it is not

The generated procedure is a correct, readable starting point, not a framework. It does not retry, cache the token across calls, or page through @odata.nextLink; those are design decisions for your extension. The guide AL HttpClient example walks through a complete codeunit, including JSON parsing and error handling, if you want to see how the pieces fit together.

Questions

Which plan includes code generation?

AL and cURL code generation are Pro features. The Free plan includes every Business Central feature, such as Explore and request bodies from $metadata.

Does the generated AL compile?

It is written to compile as a procedure inside a codeunit on current Business Central versions, using SecretText and SecretStrSubstNo for tokens. You add it to your own object and give it a name; Ava names the procedure after your request.

Does it handle OAuth2 tokens?

Yes. For OAuth2 client credentials, the generated code includes an AcquireAccessToken procedure that posts to the Microsoft Entra token endpoint and returns the token as a SecretText.

Can I generate code for a custom API page?

Yes. Code is generated from whatever request you sent, so a call to api/<publisher>/<group>/<version> works exactly like one to the standard API.