BC16 webservices / API DeepInsert

kef
Member Posts: 7
Hi,
I'm working on a webservice / api which will is running on a BC16 OnPrem environment.
It has been working out great so far, but I experience a lot of issues, when trying to insert data with header and lines.
I have created my example code on https://github.com/kefdk/bc16-api
(yes, I have been reading on this blog-post: https://www.kauffmann.nl/2020/07/01/deep-insert-with-business-central-apis-part-2/ :-))
My JSON body data for the post-request (through Postman) looks like this:
I would expect this body data to create a header and two lines attached to this header. The header is created successfully, but the lines are not to be found.
I can see from various posts around the net that a lot of people are having the same problem as me, but I cannot find a solution for this. I would believe that this should be possible to do.
Do anyone in here have any ideas to a solution?
Thanks in advance, and have a great day!
/Kristian
I'm working on a webservice / api which will is running on a BC16 OnPrem environment.
It has been working out great so far, but I experience a lot of issues, when trying to insert data with header and lines.
I have created my example code on https://github.com/kefdk/bc16-api
(yes, I have been reading on this blog-post: https://www.kauffmann.nl/2020/07/01/deep-insert-with-business-central-apis-part-2/ :-))
My JSON body data for the post-request (through Postman) looks like this:
{
"description": "Test 1",
"headerslines": [
{
"description": "Line 1"
},
{
"description": "Line 2"
}
]
}
I would expect this body data to create a header and two lines attached to this header. The header is created successfully, but the lines are not to be found.
I can see from various posts around the net that a lot of people are having the same problem as me, but I cannot find a solution for this. I would believe that this should be possible to do.
Do anyone in here have any ideas to a solution?
Thanks in advance, and have a great day!
/Kristian
0
Answers
-
Hi Kristian,
please try the following:
In file MyExampleHeaderAPI.Page.al, changepart(lines; "My Example Header Line API")
topart(headerslines; "My Example Header Line API")
the name of your part has to match the entitysetname in order for deep insert to work.
0 -
Hi @foo_bar
I have already tried that. The problem is that the OData service it self it taking the EntitySetName from the Header API Page and adds the lines afterwards.
When I call the service today with the code on GitHub and with a GET, I also get headerslines out as a list for each header. If I manually my self add the headerslines to the part, then I need to do the expand= with headersheaderslines.
I think the MS Documentation around this area is missing some information, because their own example (https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-custom-api) does not work either.
But thank you for the idea.
/Kristian0 -
Hi Kristian,
I have forked your repo, implemented my change, and I have following result when trying your payload with postman. This seems to work for me?
0 -
I ran into this couple of years ago and then I had the problem @foo_bar pointed out
https://forum.mibuso.com/discussion/72423/api-deep-insert-not-working-in-custom-entity#latest1 -
Hi @foo_bar ,
I still haven't gotten this to work, however I think the reason as of now is actually the difference between OData setup (through web service setup in BC) and BC APIs. Looks like it for you work on a BC17 with the APIs, while for me on BC16 using OData (not the APIs) that it does not.
Right now I'm structling with the APIs instead, which gives me a lot of other issues.
Thanks for your help :-)
/kef0 -
Yes, this only works on the API endpoint.
Since it said API in your title, and you created an API page in your repo, I thought this is what you were using : )
Feel free to post your other issues, I'm sure we will be able to help you out.
0 -
Of course :-)
How ever my problem right now is that the "Integrate APIs" on the API Setup page doesn't do anything. Stands for a while (1 - 2 minutes), but the result is nothing. A bit weird, so I'm going through the whole setup to see if anything is missing somewhere.0
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