Guide
How to test a custom API page in Business Central
Updated 21 November 2026
A custom API page gives your extension its own REST endpoint, with the same shape as Microsoft's standard API. Testing one is mostly a matter of knowing which page properties decide the URL, where to find the page's own $metadata, and what each failure is telling you. This guide walks through all three, with a small page as the example.
The page, and the URL it produces
Here is an API page over a custom table of delivery routes:
page 50120 "Delivery Route API"
{
PageType = API;
APIPublisher = 'contoso';
APIGroup = 'logistics';
APIVersion = 'v1.0';
EntityName = 'deliveryRoute';
EntitySetName = 'deliveryRoutes';
EntityCaption = 'Delivery Route';
EntitySetCaption = 'Delivery Routes';
SourceTable = "Delivery Route";
DelayedInsert = true;
ODataKeyFields = SystemId;
Extensible = false;
layout
{
area(Content)
{
repeater(General)
{
field(id; Rec.SystemId) { Editable = false; }
field(code; Rec.Code) { }
field(description; Rec.Description) { }
field(driverName; Rec."Driver Name") { }
field(active; Rec.Active) { }
field(lastModifiedDateTime; Rec.SystemModifiedAt) { Editable = false; }
}
}
}
}
Five properties shape the address. APIPublisher, APIGroup and APIVersion form the API root; EntitySetName is the collection in the URL; EntityName is the type name you will see in $metadata. Together they give:
https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/<environment>/api/contoso/logistics/v1.0/companies(<company-id>)/deliveryRoutes
Every segment is case-sensitive. DeliveryRoutes is not deliveryRoutes, and the server answers "Resource not found" rather than guessing.
The names inside field(…) are the names in the JSON: driverName, not "Driver Name". Microsoft's convention is camelCase, and following it means your API reads like the standard one. ODataKeyFields = SystemId makes a record addressable by its GUID, deliveryRoutes(<id>), the same way standard entities are. DelayedInsert = true is required: without it the record would be inserted the moment the first field arrived, before the rest of the body was applied, and any required field would fail validation.
The sign-in is the same as for the standard API. If you can call companies, you can call this. Connect to the Business Central API with OAuth 2.0 covers the setup.
1. Read its $metadata first
Before sending a single request to the page, fetch the API root's description:
GET https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/<environment>/api/contoso/logistics/v1.0/$metadata
Authorization: Bearer <access-token>
It lists every API page your extension publishes under that publisher, group and version, with its entity type, fields, types and key:
<EntityType Name="deliveryRoute">
<Key><PropertyRef Name="id" /></Key>
<Property Name="id" Type="Edm.Guid" Nullable="false" />
<Property Name="code" Type="Edm.String" MaxLength="20" />
<Property Name="description" Type="Edm.String" MaxLength="100" />
<Property Name="driverName" Type="Edm.String" MaxLength="50" />
<Property Name="active" Type="Edm.Boolean" />
<Property Name="lastModifiedDateTime" Type="Edm.DateTimeOffset" />
</EntityType>
<EntitySet Name="deliveryRoutes" EntityType="Microsoft.NAV.deliveryRoute" />
If your page is not in it, nothing else will work, and the reason is in the list below under "Resource not found". If it is, you now know the exact names and types to use. Reading $metadata and building JSON bodies goes through the document in more detail.
2. List and filter
GET .../api/contoso/logistics/v1.0/companies(<company-id>)/deliveryRoutes?$filter=active eq true&$select=code,description,driverName&$top=20
The standard query options all apply: $filter, $select, $orderby, $top, $skip and $count. A good first check is that $filter on each field you care about returns what you expect, especially enums and dates, where a type mismatch produces a 400 rather than an empty list.
Then read one record by its key:
GET .../deliveryRoutes(7a1e0b2c-3d4f-4a5b-8c6d-9e0f1a2b3c4d)
The response carries @odata.etag, which you will need for the update in a moment.
3. Create
POST .../api/contoso/logistics/v1.0/companies(<company-id>)/deliveryRoutes
Content-Type: application/json
{
"code": "NORTH-01",
"description": "North side, mornings",
"driverName": "A. Patel",
"active": true
}
A 201 Created returns the record as stored, with the id the server assigned. Compare it with what you sent: a field that came back different was changed by table code, and a field that came back empty was ignored, usually because the page control is not editable or the field name was wrong.
Unknown property names are not an error on a POST; they are simply dropped. If a value is not sticking, that is the first thing to check, and $metadata settles it.
4. Update and delete
PATCH .../deliveryRoutes(7a1e0b2c-3d4f-4a5b-8c6d-9e0f1a2b3c4d)
Content-Type: application/json
If-Match: W/"JzE5OzEyMzQ1Njc4OTA7Jw=="
{
"driverName": "B. Okafor"
}
Send only the fields you are changing, and the record's current ETag in If-Match. Leave the header out and the call fails with BadRequest_InvalidToken; send a stale one and it fails with Request_EntityChanged. Fixing If-Match and ETag errors explains both. DELETE takes the same URL and the same header, and answers 204 No Content.
5. Bound actions
A procedure on the page marked [ServiceEnabled] becomes an action you can call with a POST:
[ServiceEnabled]
procedure Activate(var ActionContext: WebServiceActionContext)
begin
Rec.Validate(Active, true);
Rec.Modify(true);
ActionContext.SetObjectType(ObjectType::Page);
ActionContext.SetObjectId(Page::"Delivery Route API");
ActionContext.AddEntityKey(Rec.FieldNo(SystemId), Rec.SystemId);
ActionContext.SetResultCode(WebServiceActionResultCode::Updated);
end;
POST .../deliveryRoutes(7a1e0b2c-3d4f-4a5b-8c6d-9e0f1a2b3c4d)/Microsoft.NAV.activate
The action's name in the URL is the procedure's name in camelCase, under the Microsoft.NAV namespace, and it appears in $metadata as an Action bound to the entity type. No body is needed unless the procedure takes parameters, in which case they go in a JSON object by name. The result code you set decides the HTTP status: Updated gives 200 with the record, Deleted gives 204.
Versions
Microsoft's convention is beta while a page is still changing and v1.0, v2.0 once clients depend on it. A page can list several: APIVersion = 'beta', 'v1.0'; publishes the same page under both roots, so a consumer on beta keeps working while new ones start on v1.0. Test each version you publish; they are separate endpoints with separate $metadata, and a change to one is not a change to the other.
API pages and ODataV4 web services are not the same
Business Central has an older way to expose a page: register it on the Web Services page and it appears under /ODataV4/:
GET https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/<environment>/ODataV4/Company('CRONUS USA, Inc.')/DeliveryRoutes
The differences matter when you are testing, because the two behave differently:
| What | API page | ODataV4 web service |
|---|---|---|
| Address | /api/<publisher>/<group>/<version>/companies(<id>)/… | /ODataV4/Company('<name>')/<ServiceName> |
| Published by | Installing the extension | A row on the Web Services page, per company or all |
| Field names | The field(…) names you chose | Derived from the page's control names, often with underscores |
| Key | ODataKeyFields, usually SystemId | The table's primary key, as ('NORTH-01') |
| Versioning | APIVersion, several at once | None; changing the page changes the service |
$metadata | Per API root | One document for every published service, usually large |
Any page can be published as a web service, which makes it quick for a one-off export. For anything another system will depend on, build an API page: it is versioned, it is installed with your app, and its names are yours to decide.
Common failures
| What you see | Cause | Fix |
|---|---|---|
404 BadRequest_ResourceNotFound: Resource not found for the segment 'deliveryRoutes' | The publisher, group, version or entity set name in the URL does not match the page, or the extension is not installed in this environment. | Fetch that root's $metadata. If the page is not listed, check the properties and that the app is installed where you are calling. |
404 on the whole $metadata | Nothing is published under that publisher, group and version. | Check the spelling of all three. They are case-sensitive. |
400 BadRequest_InvalidOperation: Control '…' is read-only | The body sets a field whose control has Editable = false, or one the table calculates. | Remove it from the body. |
| A field you sent came back empty | The property name is not on the page, so it was dropped. | Use the name from $metadata. |
400: The field … must not be blank | Table validation, raised when the record is inserted. | Include that field. If the message appears before the body is applied, check DelayedInsert. |
401 Authentication_InvalidCredentials | The token is good but Business Central refuses the app or user. | Enable the app on the Microsoft Entra applications page, and give it a permission set that covers your table. |
| The page works in one environment and not another | Different app version installed, or not installed. | Compare $metadata from both. It describes exactly what each environment has. |
| Changes to the page do not appear | The old version is still installed, or the client is caching $metadata. | Publish and install the new version, then fetch $metadata again. |
More codes and their meanings are in Business Central API errors explained.
Test in a sandbox, with a copy of production data if the logic depends on it. A POST to a custom page runs your table's OnInsert and validation code for real, and a bound action does whatever you wrote in it.
A checklist
$metadatafor the API root lists the page, with the field names and types you expect.- The list call returns records, and
$filterworks on each field a consumer will filter on. - One record can be read by key, and its
@odata.etagis present. - A create returns
201, and every field you sent is in the reply with the value you sent. - An update with
If-Matchsucceeds; one without it is refused. - A delete answers
204, and the record is gone from the list. - Each bound action returns the status its result code promises, and did what it should.
- Every version in
APIVersionpasses the same checks.
The same thing in Ava
Point Ava at your custom root and the steps above become clicks. Paste …/api/contoso/logistics/v1.0/ into a request and choose Explore: Ava reads that root's $metadata and lists your entities, their fields and their bound actions, with the entity set names and the action URLs already built. Tick deliveryRoutes and Ava adds ready-made list, get, create, update and delete requests to a collection, with If-Match: {{$etag}} on the update and delete so the ETag is never copied by hand.
In a request's Body tab, From metadata… builds the JSON from your own page's fields, with the right types, leaving out the ones the server sets. When a call is refused, Ava shows Business Central's own message and the field it names. Explore works from any URL under an API root, so it covers the standard API, custom API pages and ODataV4 web services alike.
