microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
733 stars 243 forks source link

BC returns error when trying to create a subscription to an endpoint based on table "BOM Component" #6549

Closed clagoa closed 3 years ago

clagoa commented 3 years ago

Hi guys,

I have been creating a custom API to use as WebHook (Subscription) from an external application. I have created endpoints on several tables (products, customers, vendors, Item Ledger Entries) and everything works correctly except when I try to subscribe to the BOM Component endpoint.

1. Describe the bug Business Central response an error when create a subscription on a API Endpoint based on the "BOM Component" table.

2. To Reproduce

  1. Define a page API like this:

       page 50150 "BOMComponentApi.Azm"
        {
            PageType = API;
            SourceTable = "BOM Component";
            Caption = 'BOM Component (API)';
            APIPublisher = 'publisher';
            APIGroup = 'group';
            APIVersion = 'v1.0';
            EntityName = 'bomComponent';
            EntitySetName = 'bomComponents';
            Editable = false;
            InsertAllowed = false;
            ModifyAllowed = false;
            DeleteAllowed = false;
            DelayedInsert = true;
            DataAccessIntent = ReadOnly;
    
            layout
            {
                area(Content)
                {
                    group(GroupName)
                    {
                        field(parentItemNo; Rec."Parent Item No.")
                        {
                            ApplicationArea = All;
                            ToolTip = 'Specifies the value of the Parent Item No. field';
                        }
                        field(lineNo; Rec."Line No.")
                        {
                            ApplicationArea = All;
                            ToolTip = 'Specifies the value of the Parent Item No. field';
                        }
                        field(type; Rec.Type)
                        {
                            ApplicationArea = All;
                            ToolTip = 'Specifies the value of the Type field';
                        }
                        field(no; Rec."No.")
                        {
                            ApplicationArea = All;
                            ToolTip = 'Specifies the value of the No. field';
                        }                
                    }
                }
            }
        }
  2. Publish and create a subscription throw the API with a POST request like this:

      POST https://api.businesscentral.dynamics.com/v2.0/{{{{tenantId}}}}/Sandbox/api/publisher/group/v1.0/subscriptions HTTP/1.1
      Content-Type: application/json
      Authorization: Basic {{username}}:{{password}}
    
      {
        "notificationUrl": "{{notificationURL}}",
        "resource": "/api/publisher/group/v1.0/companies({{companyId}})/bomComponents",
        "clientState": "BomComponent_01293801928391804"
      }

3. Expected behavior BC must return a 200 HTTP code and create the subscription

4. Actual behavior BC returns a 400 HTTP code error and the subscription is not created: image

5. Versions:

The extension "ALProject21" only contains the BOM Component API page.

clagoa commented 3 years ago

Hi again,

I've been talking to Microsoft Support and It seems that you can't create API subscription with a composite primary key. In this case, It was using the primary key of the "BOM Component" table, which is: "Parent Item No.", "Line No.".

The solution was simple, just add the SystemId field to the page and set it as OdataKeyFields.

image