Deepinserts not working

jordi79jordi79 Member Posts: 280
edited 02:18 in NAV Three Tier
I have been trying to create an api page with subpage that allows deepinserts, but have failed in doing so. I have seen many other working examples, but could not get mine to work. I have been looking at https://github.com/manjusree16/AL-Demos/blob/master/CustomAPIorderExample/Table/Call_API.http and was able to duplicate his work. But when I try to do the same on a SalesInvoice, I fail to do so.

My code:
page 50715 apigrpSalesInv
{
    APIGroup = 'apigrp';
    APIPublisher = 'apipub';
    APIVersion = 'v2.0';
    ApplicationArea = All;
    Caption = 'apigrpSalesInv', Locked = true;
    DelayedInsert = true;
    EntityName = 'apigrpSalesInv';
    EntityCaption = 'apigrpSalesInv', Locked = true;
    EntitySetName = 'apigrpSalesInvs';
    EntitySetCaption = 'apigrpSalesInvs', Locked = true;
    PageType = API;
    SourceTable = "Sales Header";
    SourceTableView = where("Document Type" = FILTER(Invoice));
    ODataKeyFields = "No.";
    Extensible = false;
    ChangeTrackingAllowed = true;

    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field(no; Rec."No.")
                {
                    Caption = 'No.';
                }
                field(sellToCustomerNo; Rec."Sell-to Customer No.")
                {
                    Caption = 'Sell-to Customer No.';
                }
                field(postingDate; Rec."Posting Date")
                {
                    Caption = 'Posting Date';
                }
                part(apigrpSalesInvLines; apigrpSalesInvLine)
                {
                    ApplicationArea = All;
                    Caption = 'apigrpSalesInvLines', Locked = true;
                    EntityName = 'apigrpSalesInvLine';
                    EntitySetName = 'apigrpSalesInvLines';
                    SubPageLink = "Document Type" = field("Document Type"), "Document No." = field("No.");
                    //Multiplicity = Many;
                }

            }
        }
    }
}

page 50714 apigrpSalesInvLine
{
    APIGroup = 'apigrp';
    APIPublisher = 'apipub';
    APIVersion = 'v2.0';
    ApplicationArea = All;
    Caption = 'apigrpSalesInvLine', Locked = true;
    DelayedInsert = true;
    EntityName = 'apigrpSalesInvLine';
    EntityCaption = 'apigrpSalesInvLine', Locked = true;
    EntitySetName = 'apigrpSalesInvLines';
    EntitySetCaption = 'apigrpSalesInvLines', Locked = true;
    PageType = API;
    UsageCategory = Lists;
    //PageType = ListPart;
    SourceTable = "Sales Line";
    SourceTableView = where("Document Type" = FILTER(Invoice));
    ODataKeyFields = "Document Type", "Document No.", "Line No.";
    Extensible = false;
    ChangeTrackingAllowed = true;
    InsertAllowed = true;
    AutoSplitKey = true;
    PopulateAllFields = true;

    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field(documentType; Rec."Document Type")
                {
                    ToolTip = 'Specifies the type of document that you are about to create.';
                }
                field(documentNo; Rec."Document No.")
                {
                    Caption = 'Document No.';
                }
                field(lineNo; Rec."Line No.")
                {
                    Caption = 'Line No.';
                }
                field("type"; Rec."Type")
                {
                    Caption = 'Type';
                }
                field(no; Rec."No.")
                {
                    Caption = 'No.';
                }
                field(description; Rec.Description)
                {
                    Caption = 'Description';
                }
                field(quantity; Rec.Quantity)
                {
                    Caption = 'Quantity';
                }
                field(unitPrice; Rec."Unit Price")
                {
                    Caption = 'Unit Price';
                }
            }
        }
    }
}

POST request
POST /BC/api/apipub/apigrp/v2.0/companies(bb48a1cd-88b6-ef11-b8eb-6045bdc89e63)/apigrpsalesinvs?$expand=apigrpSalesInvLines HTTP/1.1
Content-Type: application/json
Authorization: Basic YWRtaW46UEBzc3cwcmQ=
User-Agent: PostmanRuntime/7.43.4
Accept: */*
Host: bcserver3-default:7048
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 465
 
{
"no": "INV002",
"sellToCustomerNo": "10000",
"postingDate": "2025-11-16",
"apigrp": [
{
"lineNo": 1,
"type": "Item",
"no": "1896-S",
"description": "test 1",
"quantity": 1,
"unitPrice": 100
},
{
"lineNo": 2,
"type": "Item",
"no": "2000-S",
"description": "test 2",
"quantity": 1,
"unitPrice": 200
}
]
}
 
HTTP/1.1 201 Created
Cache-Control: no-cache, no-store
Transfer-Encoding: chunked
Content-Type: application/json; odata.metadata=minimal; odata.streaming=true
Content-Encoding: br
Location: http://bcserver3-default:7048/BC/api/apipub/apigrp/v2.0/companies(bb48a1cd-88b6-ef11-b8eb-6045bdc89e63)/apigrpSalesInvs('INV002')
Vary: Accept-Encoding
Server: Microsoft-HTTPAPI/2.0
urls-rewritten-to-public: false
OData-Version: 4.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: Date, Content-Length, Server, OData-Version
request-id: 75c96f3a-1507-486b-bf1c-44e38ca729d2
Date: Thu, 08 May 2025 02:11:58 GMT
 
{"@odata.context":"http://bcserver3-default:7048/BC/api/apipub/apigrp/v2.0/$metadata#companies(bb48a1cd-88b6-ef11-b8eb-6045bdc89e63)/apigrpSalesInvs/$entity","@odata.etag":"W/\"JzIwOzE3NTU0ODQ4MjIzODc5MzIwNTA2MTswMDsn\"","no":"INV002","sellToCustomerNo":"10000","postingDate":"2025-11-16","apigrpSalesInvLines":[]}
Sign In or Register to comment.