API page type

Pages of the type API are used to create versioned, webhook-supported, OData v4 enabled REST web services. This type of page can't be displayed in the user interface, but is intended for building reliable integration services. When creating this page type, you must specify many properties that provide information for the web service endpoint. Use the snippet tpage - Page of type API to get the right template and the list of these properties automatically filled in. This page type can't be extended by creating a page extension object. Instead, you must create a new API by adding a page object.

Pages of the type API can be used to develop a custom API. For more information, see Developing a Custom API.

Note

Extending API pages and queries isn't currently possible in Business Central.

Naming conventions

For the API page type, the following naming conventions exist:

  • camelCase for naming attributes, tables, and APIPublisher, APIGroup, EntityName, and EntitySetName.
  • Alphanumeric characters allowed (A-Z+a-z+0-9) in above elements.
  • APIVersion follows the pattern vX.Y or beta.

At design time, the compiler shows warnings on casing violations and errors on naming violations. Once an API page is deployed, the corresponding $metadata is exposed on the endpoint of the page.

Tip

Use Ctrl+Space to trigger IntelliSense and get assistance on code completion, parameter info, quick info, and member lists. For more information about snippets, see Syntax and snippets.

Create, read, update, and delete operations

API pages support create, read, update, and delete operations. If you want to disallow, create, update, and delete operations, you can use the InsertAllowed, ModifyAllowed, and DeleteAllowed properties respectively.

If you only want your API to expose committed data, you can add an OnOpenPageTrigger like this:

    trigger OnOpenPage()
    begin
        Rec.ReadIsolation := IsolationLevel::ReadCommitted;
    end;

Example of the API page type

The following page example publishes an API available at: ../contoso/app1/v2.0/companies({id})/customers. The APIVersion can be specified as one version, or a list of versions, if the API is supported through multiple versions.

page 50120 MyCustomerApi
{
    PageType = API;
    Caption = 'My Customer API';
    APIPublisher = 'contoso';
    APIGroup = 'app1';
    APIVersion = 'v2.0', 'v1.0';
    EntityName = 'customer';
    EntitySetName = 'customers';
    SourceTable = Customer;
    DelayedInsert = true;
    
    layout
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(id; Id)
                {
                    Caption = 'ID';
                }
                field(name; Name)
                {
                    Caption = 'Name';
                }
            }
        }
    }
}

See also

API developer overview AL development environment
API query type
Walkthrough: developing a custom API
Page extension object
APIPublisher property
APIGroup property
APIVersion property
EntityName property
EntitySetName property
Developing extensions