Design API pages and queries for integration workloads

Completed

API pages and API queries are optimized AL object types for Business Central integrations. Choose the object type from the operations and data shape that the external application needs.

Choose an API page or API query

An API page exposes records from one source table as entities. It supports the standard HTTP operations associated with that entity when the page and permissions allow them.

Requirement API page behavior
Retrieve entities Supports GET for collections and individual records.
Create an entity Supports POST.
Change an entity Supports PATCH with concurrency control.
Remove an entity Supports DELETE.
Run an entity operation Can expose a service-enabled bound action.

An API query exposes a read-only result set. It can join data items, add filters, and aggregate values, but consumers can't create or change records through it. Use an API query for analytical projections, synchronization feeds, and purpose-built read models.

Don't expose a user-interface page when an API object meets the requirement. UI pages can contain triggers, FactBoxes, calculated fields, and presentation logic that add work without improving the external contract. API objects also make the published field list explicit.

Define a stable API page

An API page identifies its route and entity through object properties.

page 71300 "Integration Customer API"
{
    PageType = API;
    APIPublisher = 'training';
    APIGroup = 'integration';
    APIVersion = 'v1.0';
    EntityName = 'integrationCustomer';
    EntitySetName = 'integrationCustomers';
    EntityCaption = 'Integration customer';
    EntitySetCaption = 'Integration customers';
    SourceTable = Customer;
    ODataKeyFields = SystemId;
    DelayedInsert = true;
    Extensible = false;

    layout
    {
        area(Content)
        {
            repeater(Records)
            {
                field(id; Rec.SystemId)
                {
                    Caption = 'Id';
                    Editable = false;
                }
                field(number; Rec."No.")
                {
                    Caption = 'Number';
                }
                field(displayName; Rec.Name)
                {
                    Caption = 'Display name';
                }
                field(email; Rec."E-Mail")
                {
                    Caption = 'Email';
                }
                field(lastModifiedDateTime; Rec.SystemModifiedAt)
                {
                    Caption = 'Last modified date time';
                    Editable = false;
                }
            }
        }
    }
}

APIPublisher, APIGroup, and APIVersion form the custom API route. Treat these values and the entity names as a public contract. Changing them breaks existing callers. Add a new version when a breaking change is required.

Use a single GUID field as ODataKeyFields. SystemId is immutable and exists on every table, so it remains stable when a business key such as customer number changes. DelayedInsert = true lets the platform collect all supplied values before it inserts a new entity.

Use camelCase field names in the API layout. Expose only fields that belong to the contract. A field omitted from the layout isn't available to callers. For PATCH operations, callers supply the entity's current @odata.etag value in the If-Match header to prevent an update from overwriting a newer change.

Build a read-only API query

An API query uses endpoint properties similar to an API page but defines columns and filters through query data items.

query 71301 "Customer Snapshot API"
{
    QueryType = API;
    APIPublisher = 'training';
    APIGroup = 'integration';
    APIVersion = 'v1.0';
    EntityName = 'customerSnapshot';
    EntitySetName = 'customerSnapshots';
    Caption = 'Customer snapshots';
    DataAccessIntent = ReadOnly;

    elements
    {
        dataitem(Customer; Customer)
        {
            column(id; SystemId)
            {
                Caption = 'Id';
            }
            column(number; "No.")
            {
                Caption = 'Number';
            }
            column(displayName; Name)
            {
                Caption = 'Display name';
            }
            column(email; "E-Mail")
            {
                Caption = 'Email';
            }
            column(lastModifiedDateTime; SystemModifiedAt)
            {
                Caption = 'Last modified date time';
            }
        }
    }
}

The query is read-only by design. DataAccessIntent = ReadOnly also declares that its GET workload doesn't depend on writes. Keep query columns focused and avoid expensive calculations when the consumer doesn't need them. Use OData query options such as $select, $filter, $orderby, and $top to reduce response size.

API pages and API queries become available when the extension is installed. They don't need entries on the Web Services page. Their route follows this pattern:

https://api.businesscentral.dynamics.com/v2.0/{tenantId}/{environmentName}/api/{publisher}/{group}/{version}/companies({companyId})/{entitySetName}

For more information, see Develop a custom API and API query type.