Deep insert in API page problems

skollops
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
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:
And the page used in the part:
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;
0
Best Answer
-
Hi Skollops,
in your docker url you are using the API endpoint, in your BC online url you are using the ODataV4 endpoint (this endpoint does not support deep inserts)
try changing
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/ODataV4/Company('{{company2}}')/salesReturnOrder?$expand=items
to
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/api/{{publisher}}/{{apiGroup}}/v1.0/companies({{company}})/salesReturnOrder?$expand=items1
Answers
-
I don't think the PageType of the subpage should be API, it should be ListPart.1
-
Unrelated, I did a lot of API stuff in NAV 2018 and then it was not possible to have three level down like you are trying with the serialNo. Is that possible now?
If you run into problem with that then you can try complex types.
https://forum.mibuso.com/discussion/72539/nav-2018-api-complex-types#latest0 -
I don't think the PageType of the subpage should be API, it should be ListPart.Unrelated, I did a lot of API stuff in NAV 2018 and then it was not possible to have three level down like you are trying with the serialNo. Is that possible now?
If you run into problem with that then you can try complex types.
https://forum.mibuso.com/discussion/72539/nav-2018-api-complex-types#latest
Same answer as aboveIt works in docker, but not here.
Thank you for your responses though!0 -
Hi Skollops,
in your docker url you are using the API endpoint, in your BC online url you are using the ODataV4 endpoint (this endpoint does not support deep inserts)
try changing
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/ODataV4/Company('{{company2}}')/salesReturnOrder?$expand=items
to
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/api/{{publisher}}/{{apiGroup}}/v1.0/companies({{company}})/salesReturnOrder?$expand=items1 -
@wait ,
It is now possible to nest API pages, if you want to expand nested collections, you can use this format for this example
https://api.businesscentral.dynamics.com/v1.0/{{tenant}}/{{environment}}/api/{{publisher}}/{{apiGroup}}/v1.0/companies({{company}})/salesReturnOrder?$expand=items($expand=serialNos)
@skollops , I just noticed a little error in your Items_REAP pagepart(serialNo; serialNo_REAP) { EntityName = 'serialNo'; EntitySetName = 'serialNo'; SubPageLink = "Item No." = field("No."), "Source ID" = field("Document No."); }
should bepart([b]serialNos[/b]; serialNo_REAP) { EntityName = 'serialNo'; EntitySetName = '[b]serialNos[/b]'; SubPageLink = "Item No." = field("No."), "Source ID" = field("Document No."); }
and then also be sure to check your settings (entityname, entitysetname) on your serialNo_REAP page1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions