MSBA-353 · Lesson 1 of 12 · 22 min
API pages and web services
▶ Video coming soon A video version of this lesson is on the way.
By late September 2026, Corbel & Finch had a configured Business Central company in the CONFIG environment, a chart of accounts, items, price lists and a go-live date of January 1, 2027. What it did not have was a way for anything else to talk to Business Central. The web shop still emailed a daily order summary to Callum, the cafés' point-of-sale system produced a spreadsheet, and the parcel carrier lived in a browser tab. "Every one of those is a door," Noor Haddad-Kessel told Callum at the first integration session. "Our job this autumn is to decide which doors open, who has a key, and what happens when somebody leaves one open." This course follows that work: the APIs, flows, external calls, Copilot feature, tests, upgrades, telemetry, pipelines and publishing that turn the AL skills from MSBA-352, AL Development for Business Central, into apps that run safely in production.
The MB-820 study guide, in the version measured from November 20, 2026, gives the domain "Integrate Business Central with other applications" a weight of 15 to 20 percent, up from the previous outline. Under it sit three skill groups: accessing external REST services, implementing APIs by using AL, and building Copilot capability by using AL. This lesson covers the second group, starting with the web services Business Central already exposes.
Three kinds of web service
Business Central online publishes data and logic over HTTPS in three ways. Each uses the same security model, OAuth through Microsoft Entra ID, but they differ in how stable their contracts are and who designs them.
| Kind | What is exposed | Contract | Typical use |
|---|---|---|---|
| Standard APIs (v2.0) | Microsoft's API pages and queries, such as customers, items, salesOrders and generalLedgerEntries | Versioned and stable; Microsoft does not break v2.0 | Most integrations that need common entities |
| Custom APIs | API pages and API queries written in an extension, with their own publisher, group and version | Stable as long as the developer versions them properly | Entities or fields the standard APIs lack |
| OData and SOAP web services | Any page, query or codeunit published on the Web Services page | Changes whenever the underlying page or codeunit changes | Quick reports, Excel and Power BI connections, legacy integrations |
The distinction that matters is the contract. A UI page published as an OData web service exposes whatever fields the page shows today. If a user personalizes the page, or an update moves a field, the integration sees the change. API pages are built for machines: they have stable field names in camel case, a version in the URL and no UI at all. Microsoft's guidance is to use the standard APIs where they cover the need, build custom APIs where they do not, and keep UI pages published as OData for read-only tools such as Excel or Power BI.
Endpoints and URLs
Every Business Central online endpoint starts with the same host, api.businesscentral.dynamics.com, followed by v2.0, the Microsoft Entra tenant ID and the environment name. After that the path splits. The standard API path continues with api/v2.0 and then the company. A custom API continues with api, then its own publisher, group and version. An OData web service continues with ODataV4 and the company name. Callum found the endpoint addresses for published services on the Web Services page, which lists each service with its OData V4 URL.
GET https://api.businesscentral.dynamics.com/v2.0/{tenantId}/CONFIG/api/v2.0/companies
GET https://api.businesscentral.dynamics.com/v2.0/{tenantId}/CONFIG/api/v2.0/companies({companyId})/items?$filter=itemCategoryCode eq 'BLEND'&$select=number,displayName,inventory
GET https://api.businesscentral.dynamics.com/v2.0/{tenantId}/CONFIG/api/quarrystone/roastery/v1.0/companies({companyId})/cafeStock
GET https://api.businesscentral.dynamics.com/v2.0/{tenantId}/CONFIG/ODataV4/Company('Corbel%20%26%20Finch')/ItemListOData gives every endpoint the same query language: a filter option to select records, a select option to choose fields, an expand option to include related entities such as a sales order's lines, a top option to limit rows and an orderby option to sort. Asking only for the fields and rows needed is the simplest performance habit in integration work. The web shop does not need forty fields of every item to show availability; it needs the number, the name and the quantity.
Authentication: Microsoft Entra apps
Business Central online accepts only OAuth for web services. Basic authentication with web service access keys was removed years ago, so every integration needs a Microsoft Entra identity. There are two patterns. Delegated access acts as a signed-in user, which suits tools a person runs, such as Excel or Power BI. Service-to-service access, using the OAuth client credentials flow, lets a background service sign in as itself, with no user present.
For the web shop's nightly order import, Noor set up service-to-service access in three steps. In the Microsoft Entra admin center she registered an application, created a client secret stored in the web shop's key vault, and granted it the Business Central application permission for API access with admin consent. Then, in Business Central, she opened the Microsoft Entra Applications page and created a card for the application's client ID, with a description, a state of Enabled, and permission sets limited to what the integration needs. The app signs in as its own Business Central user, so its changes show up in the change log and in telemetry under a recognizable name.
| Integration | Pattern | Permissions granted in Business Central |
|---|---|---|
| Web shop order import | Service-to-service | A custom permission set: insert sales documents, read items, customers and prices |
| Web shop availability feed | Service-to-service, same app | Read access to the cafeStock API |
| Callum's Excel price check | Delegated | His own user permissions |
| Bettina's Power BI sales report | Delegated | Her own user permissions |
The least-privilege rule from MSBA-150 applies to apps as much as to people. An integration app with SUPER can do anything, which means a leaked client secret could do anything. Noor's rule was one Entra app per external system, one permission set per app, and a secret rotation date in the project plan.
Building a custom API page
The web shop needed something the standard APIs do not offer: available quantity for each roasted coffee at the roastery, net of open wholesale orders, in one call. Noor built it as a custom API page in CF Roastery, Quarrystone's integration extension for Corbel & Finch, which uses object IDs 50000 to 50099 and the prefix CFR; the warranty extension from MSBA-352, Corbel & Finch Warranty, sits beside it in 50100 to 50149 with the affix CNF. An API page is an ordinary AL page with PageType = API and a set of properties that define its address and behaviour.
page 50040 "CFR Coffee Availability API"
{
PageType = API;
APIPublisher = 'quarrystone';
APIGroup = 'roastery';
APIVersion = 'v1.0';
EntityName = 'coffeeAvailability';
EntitySetName = 'coffeeAvailability';
EntityCaption = 'Coffee Availability';
EntitySetCaption = 'Coffee Availability';
SourceTable = Item;
SourceTableView = where("Item Category Code" = filter('SINGLE ORIGIN|BLEND|ESPRESSO'));
ODataKeyFields = SystemId;
Editable = false;
DataAccessIntent = ReadOnly;
Extensible = false;
layout
{
area(Content)
{
repeater(Records)
{
field(id; Rec.SystemId) { Caption = 'Id'; }
field(number; Rec."No.") { Caption = 'Number'; }
field(displayName; Rec.Description) { Caption = 'Display Name'; }
field(availableBags; AvailableBags) { Caption = 'Available Bags'; }
field(lastModifiedDateTime; Rec.SystemModifiedAt) { Caption = 'Last Modified Date Time'; }
}
}
}
var
AvailableBags: Decimal;
trigger OnAfterGetRecord()
var
Item: Record Item;
begin
Item.SetLoadFields("No.");
Item.Get(Rec."No.");
Item.SetRange("Location Filter", 'ROASTERY');
Item.CalcFields(Inventory, "Qty. on Sales Order");
AvailableBags := Item.Inventory - Item."Qty. on Sales Order";
end;
}Each property has a job. APIPublisher, APIGroup and APIVersion form the URL segments, so this page answers at api/quarrystone/roastery/v1.0. EntityName and EntitySetName name a single record and the collection, in camel case. ODataKeyFields = SystemId makes the GUID the key, so the record keeps its identity even if someone renames the item number. DelayedInsert = true is required on API pages that insert records, so that all fields from the request body are set before the insert runs; this page is read-only, so it sets Editable = false instead. DataAccessIntent = ReadOnly sends reads to a read-only database replica where available, which lesson 7 returns to. Field names in API pages are camel case without spaces or special characters, which is what callers expect from a REST API.
Two design rules prevent pain later. First, never change a published version's contract. If the web shop needs a new field that changes meaning, publish v1.1 or v2.0 alongside v1.0 and retire the old version on a schedule. Second, keep business logic out of the API page itself where possible. The page should call codeunits that the UI also uses, so posting a web shop order through the API runs exactly the same validation as entering it by hand.
API queries
Some data is better shaped by a query than a page. An API query, a query object with QueryType = API and the same publisher, group, version and entity properties, joins tables and aggregates columns in a single SQL statement. API queries are read-only. Bettina's monthly sales-by-café dashboard needed invoiced quantity and amount by item category and BUSINESS LINE dimension; Noor wrote it as an API query over value entries, which returned twelve rows a month instead of thousands of ledger lines for the reporting tool to add up.
query 50041 "CFR Sales By Line API"
{
QueryType = API;
APIPublisher = 'quarrystone';
APIGroup = 'roastery';
APIVersion = 'v1.0';
EntityName = 'salesByLine';
EntitySetName = 'salesByLine';
DataAccessIntent = ReadOnly;
elements
{
dataitem(ValueEntry; "Value Entry")
{
DataItemTableFilter = "Item Ledger Entry Type" = const(Sale);
column(postingDate; "Posting Date") { }
column(businessLine; "Global Dimension 1 Code") { }
column(itemCategory; "Item Category Code") { }
column(invoicedQuantity; "Invoiced Quantity") { Method = Sum; ReverseSign = true; }
column(salesAmount; "Sales Amount (Actual)") { Method = Sum; }
}
}
}Writing through APIs: deep inserts and bound actions
The order import is the harder direction. Each night the web shop sends the day's orders for the WEB customer. The standard salesOrders API accepts a deep insert: one POST containing the header and its salesOrderLines, created together in one transaction. If any line fails validation, the whole order fails, which is the behaviour Callum wanted, because a half-created order is worse than none.
POST .../api/v2.0/companies({companyId})/salesOrders
Content-Type: application/json
{
"customerNumber": "WEB",
"externalDocumentNumber": "WS-2026-11-0418",
"orderDate": "2026-11-20",
"salesOrderLines": [
{ "lineType": "Item", "lineObjectNumber": "FC-BRK", "quantity": 3 },
{ "lineType": "Item", "lineObjectNumber": "MR-MUG-BLK", "quantity": 1 }
]
}Posting is an action rather than a data change, so APIs expose it as an OData bound action: a procedure on an API page marked with the ServiceEnabled attribute, called with a POST to the record's URL followed by Microsoft.NAV and the action name. The standard salesOrders API has bound actions such as shipAndInvoice. A custom API can add its own: Noor added a bound action that releases a web shop order and returns a result through the WebServiceActionContext data type, which sets the response code and the record to return.
[ServiceEnabled]
procedure releaseForPicking(var ActionContext: WebServiceActionContext)
var
SalesHeader: Record "Sales Header";
ReleaseSalesDoc: Codeunit "Release Sales Document";
begin
SalesHeader.GetBySystemId(Rec.SystemId);
ReleaseSalesDoc.PerformManualRelease(SalesHeader);
ActionContext.SetObjectType(ObjectType::Page);
ActionContext.SetObjectId(Page::"CFR Web Order API");
ActionContext.AddEntityKey(Rec.FieldNo(SystemId), Rec.SystemId);
ActionContext.SetResultCode(WebServiceActionResultCode::Updated);
end;An unbound action is not tied to a record. It comes from a codeunit published as a web service on the Web Services page; each public procedure becomes an action called at the ODataV4 endpoint as the service name, an underscore and the procedure name. Unbound actions suit operations such as "recalculate today's café restock" that work on many records at once. The MB-820 outline names both: create and manage OData bound and unbound actions.
Webhooks: being told instead of asking
The web shop also needed to know when a coffee was blocked or renamed. Polling every five minutes would work, but it wastes calls and still lags. Webhooks reverse the direction: the subscriber registers a notification URL, and Business Central calls it when records change.
The subscriber posts to the subscriptions endpoint with a notificationUrl, the resource to watch, such as a company's items collection, and an optional clientState value that Business Central echoes in every notification so the subscriber can check that the call is genuine. Business Central then performs a handshake: it calls the notification URL with a validation token, and the subscriber must return that token with 200 OK within a short time. Subscriptions expire after three days; the subscriber renews with a PATCH to the subscription, which repeats the handshake.
Notifications are lightweight. Each lists the subscription, the resource that changed and a change type of created, updated, deleted or collection; the subscriber then calls the API to read the data. Business Central waits about 30 seconds after the first change and sends one notification per changed record, or a single collection notification with a filter when more than 1,000 records changed in that window. If the subscriber is unreachable, Business Central retries for up to 36 hours, but only for timeouts, throttling and server errors; any other error response deletes the subscription. Custom API pages can support webhooks too, subscribed through their own api/publisher/group/version/subscriptions path, but not when the source table is temporary, a system table, or has a composite key, and not for API queries.
Worked problem
Choosing between polling and a webhook
The web shop shows a "sold out" badge when a coffee's available bags reach zero. Availability changes dozens of times a day. Should the web shop poll the coffeeAvailability API or subscribe to a webhook?
Show solution
- Check whether the resource supports webhooks. The coffeeAvailability page calculates AvailableBags from FlowFields; a sale changes item ledger entries, not the Item record, so an item webhook would not fire when stock moves.
- Webhooks fire on changes to the API's source records. They suit master data, such as an item being blocked or renamed.
- For stock, a short poll that asks only for changed fields is simpler and accurate: every ten minutes, select number and availableBags.
- Combine them: subscribe to the standard items API for master-data changes and poll the custom API for quantities.
Answer: Use a webhook on items for blocking and renaming, and a lightweight scheduled poll of the custom API for availability, because calculated quantities do not trigger notifications on the item.
Limits and good citizenship
Business Central online protects shared capacity with limits on web service calls, such as a rate of requests per user, a maximum number of concurrent requests and a maximum time per request. A caller that exceeds them receives 429 Too Many Requests and should wait and retry with increasing delays rather than retrying at once. Page sizes are capped too, so large reads come back in pages with a next-link that the caller follows. Callum's checklist for every integration therefore included: select only needed fields, filter on the server, follow next-links, handle 429 with back-off, and run large loads outside business hours.
Common mistakes
MistakePublishing a UI page as an OData service for a production integration.
InsteadUse a standard or custom API page, whose contract does not change when the UI does.
MistakeGiving an integration's Entra app SUPER "to get it working".
InsteadCreate a dedicated permission set for the app and grant only what it needs.
MistakeChanging fields in a published API version.
InsteadAdd a new API version and retire the old one on a schedule.
MistakeForgetting to renew webhook subscriptions.
InsteadRenew with a PATCH before the three-day expiry, and recreate subscriptions that were deleted.
MistakeRetrying immediately after a 429 response.
InsteadBack off and retry with increasing delays.
Summary and key terms
- Business Central exposes standard APIs, custom APIs and OData or SOAP web services; API pages and queries have stable, versioned contracts.
- All online endpoints use OAuth with Microsoft Entra ID; service-to-service apps are registered on the Microsoft Entra Applications page with their own permission sets.
- API pages set PageType = API with publisher, group, version, entity names and ODataKeyFields = SystemId; inserting API pages need DelayedInsert.
- API queries return joined and aggregated data read-only.
- Deep inserts create a document and its lines together; bound actions use ServiceEnabled procedures, and unbound actions come from published codeunits.
- Webhooks notify subscribers after a handshake; subscriptions expire after three days and must be renewed.
- API page
- A page with PageType = API that exposes an entity through a versioned REST endpoint.
- API query
- A query object with QueryType = API that returns read-only joined or aggregated data.
- Bound action
- An OData action on a specific record, implemented as a ServiceEnabled procedure on an API page.
- Unbound action
- An OData action not tied to a record, exposed from a codeunit published as a web service.
- Deep insert
- A single POST that creates a header and its related lines in one transaction.
- Webhook
- A subscription that makes Business Central call a URL when records in a resource change.
- Service-to-service authentication
- OAuth client credentials sign-in by an application without a user present.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why does Noor key the custom API page on SystemId rather than the item number?
Show answer
SystemId is a GUID that never changes, so the record keeps its identity even if the item number is renamed.
What must a webhook subscriber do when Business Central calls its notification URL with a validation token?
Show answer
Return the token in the response body with status 200 OK, which completes the handshake.
When would you choose an API query over an API page?
Show answer
When the caller needs read-only data joined across tables or aggregated on the server.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.