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:
{
"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
Answers
please try the following:
In file MyExampleHeaderAPI.Page.al, change to
the name of your part has to match the entitysetname in order for deep insert to work.
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.
/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?
https://forum.mibuso.com/discussion/72423/api-deep-insert-not-working-in-custom-entity#latest
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 :-)
/kef
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.
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.
Just to follow up. I got it working when I use the Business Central API methodology.
The regular OData feature is not working with it.
But I'm through, my problem is solved.
Thank you for the assistance :-)