My problem is that I can't call my custom API for a specific itemId
, however when I call the normal API it works as expected.
Currently I can successfully call the normal API for a specific item like so:
myBcServer:Port/bc/api/v1.0/companies(666e508d-9abb-ea11-bbac-000d3a492c82)/items(a5dc88b9-9abb-ea11-bbac-000d3a492c82)
But when I try to do the same with my custom API:
myBcServer:Port/bc/api/contoso/app1/v2.0/companies(666e508d-9abb-ea11-bbac-000d3a492c82)/items(a5dc88b9-9abb-ea11-bbac-000d3a492c82)
I get an error:
"error": {
"code": "BadRequest_NotFound",
"message": "Bad Request - Error in query syntax. CorrelationId: f7bc0b59-45ac-4293-9f94-108d6436272c."
}
I can successfully call both API versions at /items
. Where I get a list of all the items.
The custom API page that I made looks like this:
page 50101 ItemsCustomApi
{
PageType = API;
Caption = 'API: Items';
APIPublisher = 'contoso';
APIGroup = 'app1';
APIVersion = 'v2.0';
EntityName = 'item';
EntitySetName = 'items';
SourceTable = Item;
DelayedInsert = true;
Editable = false;
layout
{
area(Content)
{
field(id; SystemId)
{
Caption = 'ID';
}
field("No"; "No.")
{
Caption = 'No.';
}
field("UnitPrice"; "Unit Price")
{
Caption = 'Unit Price';
}
field("VendorNo"; "Vendor No.")
{
Caption = 'Vendor No.';
}
}
}
}
I suspect I need to add a property to the page like CanGetById = true
. However, I don't know.
BC version run in docker: mcr.microsoft.com/businesscentral/sandbox:dk Docker version: V19.03.12
You need to set the page property ODataKeyFields
to be able to select by id:
ODataKeyFields = SystemId;