Bearbeiten

API query type

Queries of the type API are used to generate web service endpoints and this type of query can't be used to display data in the user interface. A query of the API type can be used to join data from different data sources. The data can only be viewed. When creating this query type, you must specify properties that provide information for the web service endpoint. Use the snippet tquery - Query of type API to get the right template and the list of these properties automatically filled in.

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.

Note

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

Describe the API for MCP tools

When an API page or API query is exposed as a tool through the Business Central MCP server, the server uses metadata from the API object to generate the tool description.

The MCP server determines the tool description in the following order:

  1. The AboutText property.
  2. If AboutText isn't specified, the server uses the EntitySetCaption property.
  3. If EntitySetCaption isn't available, the server uses a camel-cased version of the EntityName property.

Provide meaningful values for these properties to help MCP clients and agents understand and select the appropriate tools. Learn more about the Business Central MCP server in Model Context Protocol (MCP) in Business Central.

Example of the API query type

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

query 20000 "APIV1 - Customer Sales"
{
    QueryType = API;
    APIPublisher = 'contoso';
    APIGroup = 'app1';
    APIVersion = 'v1.0';
    Caption = 'customerSales', Locked = true;
    EntityName = 'customerSale';
    EntitySetName = 'customerSales';

    elements
    {
        dataitem(QueryElement1; Customer)
        {
            column(customerId; Id)
            {
                Caption = 'Id', Locked = true;
            }
            column(customerNumber; "No.")
            {
                Caption = 'No', Locked = true;
            }
            column(name; Name)
            {
                Caption = 'Name', Locked = true;
            }
            dataitem(QueryElement10; "Cust. Ledger Entry")
            {
                DataItemLink = "Customer No." = QueryElement1."No.";
                SqlJoinType = LeftOuterJoin;
                DataItemTableFilter = "Document Type" = FILTER (Invoice | "Credit Memo");
                column(totalSalesAmount; "Sales (LCY)")
                {
                    Caption = 'TotalSalesAmount', Locked = true;
                    Method = Sum;
                }
                filter(dateFilter; "Posting Date")
                {
                    Caption = 'DateFilter', Locked = true;
                }
            }
        }
    }
}

API developer overview
AL development environment
API page type
APIPublisher property
APIGroup property
APIVersion property
EntityName property
EntitySetName property
Query object
Developing extensions