Deep insert in API page problems

skollopsskollops Member Posts: 3
Hi,

I'm having some trouble using API in my cloud BC. I have it working in my local docker container, but the syntax seems a bit different against my cloud BC.

This path seems to work fine.
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/ODataV4/Company('{{company}}')/salesReturnOrder


However, when I want to expand on the items part of the page, the property can't be found, the error is below.
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/ODataV4/Company('{{company2}}')/salesReturnOrder?$expand=items
{
    "error": {
        "code": "BadRequest",
        "message": "Could not find a property named 'items' on type 'NAV.salesReturnOrder'.  CorrelationId:  d09b8fd3-1119-46fe-9c07-226d1bcdc726."
    }
}

So how do I expand properly? I guess the problem is the URL.
Below is a bit more information:

I had the same problem on my docker-container, but I fixed it by using another syntax in the request url. Here is the syntax I use there:
http://{{containerName}}:7048/BC/api/{{publisher}}/{{apiGroup}}/v1.0/companies({{company}})/salesReturnOrder?$expand=items
The difference I can see is that I use the publisher and apiGroup to make it clear what should be expanded.

The pages:
page 50003 "SalesReturnOrder_REAP"
{
    PageType = API;
    Caption = 'modifySalesReturnOrder';
    APIPublisher = '{{publisher}}';
    APIGroup = '{{apiGroup}}';
    APIVersion = 'v1.0';
    EntityName = 'salesReturnOrder';
    EntitySetName = 'salesReturnOrder';
    SourceTable = "Sales Header";
    DelayedInsert = true;
    ModifyAllowed = true;
    DeleteAllowed = false;

    layout
    {
        area(Content)
        {
            group(GroupName)
            {
                field(customerNo; "Sell-to Customer No.")
                {
                }

                field(documentNo; "No.")
                {
                }

                field(type; "Document Type")
                {
                }
                part(items; Items_REAP)
                {
                    ApplicationArea = All;
                    EntityName = 'item';
                    EntitySetName = 'items';
                    SubPageLink = "Document No." = field("No."), "Document Type" = Const("Return Order");
                }
            }
        }
    }
}

And the page used in the part:
page 50004 "Items_REAP"
{
    PageType = API;
    Caption = 'items';
    APIPublisher = '{{publisher}}';
    APIGroup = '{{apiGroup}}';
    APIVersion = 'v1.0';
    EntityName = 'item';
    EntitySetName = 'items';
    SourceTable = "Sales Line";
    DelayedInsert = true;
    ModifyAllowed = false;
    DeleteAllowed = false;
    layout[s][/s]
    {
        area(Content)
        {
            repeater(GroupName)
            {
                field(itemNo; "No.")
                {
                }
                field(itemType; "Type")
                {
                }
                field(itemDescription; "Description")
                {
                }
                part(serialNo; serialNo_REAP)
                {
                    EntityName = 'serialNo';
                    EntitySetName = 'serialNo';
                    SubPageLink = "Item No." = field("No."), "Source ID" = field("Document No.");
                }

            }
        }
    }

    trigger OnInsertRecord(BelowxRec: Boolean): Boolean
    begin
        Insert(true); // Call the Table trigger because the API does not call it.

        exit(false); // Must abort the Page trigger because the record has already been inserted.
    end;

Best Answer

Answers

Sign In or Register to comment.