Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Web API Query vs Page

(0) ShareShare
ReportReport
Posted on by 25

I have been using API Page to expose data and works well. see 50113 below.

I had a request to expose item data and this needs to create relationships to other tables. For example i need length so I need to create relationship to Item Unit of Measure table.

I don't see where its possible to do with on a API Page. Is this possible?

So I found out that API Queries can do this. see 50111 below
It also seems API Queries cannot handle more than one dataitem? I will have 3 that I need to setup.

The problem with this is I cannot use my header filters like I could with API Page. see image below.

The goal is for an external system to read the data from this API in a flat format. I would like the option to be able to filter on the requester side. Any advice?

page 50113 whseShipHeader
{
    APIGroup = 'AM';
    APIPublisher = 'Addie';
    APIVersion = 'v1.05';
    ApplicationArea = All;
    Caption = 'Warehouse Ship Header';
    DelayedInsert = true;
    EntityName = 'whseShipHeader';
    EntitySetName = 'whseShipHeader';
    PageType = API;
    SourceTable = "Warehouse Shipment Header";
    SourceTableView = sorting("No.") order(descending) WHERE("Completely Picked" = CONST(false));
    ODataKeyFields = SystemId;

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field(systemId; Rec.SystemId)
                {
                    Caption = 'SystemId';
                }
                field(zoneCode; Rec."Zone Code")
                {
                    Caption = 'Zone Code';
                }
                field(completelyPicked; Rec."Completely Picked")
                {
                    Caption = 'Completely Picked';
                }
                field(status; Rec.Status)
                {
                    Caption = 'Status';
                }
                field(no; Rec."No.")
                {
                    Caption = 'No.';
                }
                field(shippingAgentCode; Rec."Shipping Agent Code")
                {
                    Caption = 'Shipping Agent Code';
                }
                field(documentStatus; Rec."Document Status")
                {
                    Caption = 'Document Status';
                }
                field(locationCode; Rec."Location Code")
                {
                    Caption = 'Location Code';
                }
                field(binCode; Rec."Bin Code")
                {
                    Caption = 'Bin Code';
                }
                field(systemCreatedAt; Rec.SystemCreatedAt)
                {
                    Caption = 'SystemCreatedAt';
                }
                field(externalDocumentNo; Rec."External Document No.")
                {
                    Caption = 'External Document No.';
                }
                part(WhseShptLine; "whseShipmentLines")
                {
                    Caption = 'Lines';
                    EntityName = 'whseShipmentLine';
                    EntitySetName = 'whseShipmentLines';
                    SubPageLink = "No." = Field("No.");
                }
            }
        }
    }
}

query 50111 perfionItemQ
{
    QueryType = API;
    APIGroup = 'AM';
    APIPublisher = 'Addie';
    APIVersion = 'v1.05';
    Caption = 'perfionItemQ';
    EntityName = 'perfionItemQ';
    EntitySetName = 'perfionItemQ';


    elements
    {
        dataitem(Item; Item)
        {
            DataItemTableFilter = Type = const(Inventory), "No." = filter('AMAR55180');
            column(No; "No.") { }
            column(Description; Description) { }
            column(UnitCost; "Unit Cost") { }
            column(GTIN; GTIN) { }
            column(Blocked; Blocked) { }
            column(ReplenishmentSystem; "Replenishment System") { }
            column(InventoryPostingGroup; "Inventory Posting Group") { }
            column(VendorNo; "Vendor No.") { }
            column(VendorItemNo; "Vendor Item No.") { }
            column(ItemCategoryCode; "Item Category Code") { }
            column(LastDateTimeModified; "Last DateTime Modified") { }


            dataitem(uom; "Item Unit of Measure")
            {
                DataItemLink = "Item No." = Item."No.";
                SqlJoinType = InnerJoin;
                DataItemTableFilter = "Code" = FILTER('Each');
                column(Length; Length) { }
                column(Width; Width) { }
                column(Height; Height) { }
                column(Cubage; Cubage) { }
                column(Weight; Weight) { }
            }

            dataitem(LAX_DP_Procurement_Unit;"LAX DP Procurement Unit")
            {
                DataItemLink = "Item No." = Item."No.", "Location Code" = Item."Location Filter";
                SqlJoinType = InnerJoin;
                column(RankingCode;"Ranking Code") { }
                column(ItemClassDescription;"Item Class Description"){}

            }



        }
    }

}

pastedimage1675255869640v1.png

  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: Web API Query vs Page

    Hi

    you can bind a subpage to the main page

    In your case the subpage would be the unit of measurement.

    in the api url to call the subpage you should add the following parameter:

    WSItem?$expand=NameEntitySubpage

    learn.microsoft.com/.../devenv-develop-custom-api

    check my answer if it helped you, thanks

    Daniele

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans