BC16 webservices / API DeepInsert

kefkef 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:
{
"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

  • foo_barfoo_bar Member Posts: 91
    Hi Kristian,

    please try the following:
    In file MyExampleHeaderAPI.Page.al, change
    part(lines; "My Example Header Line API")
    
    to
    part(headerslines; "My Example Header Line API")
    

    the name of your part has to match the entitysetname in order for deep insert to work.

  • kefkef Member Posts: 7
    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.

    /Kristian
  • foo_barfoo_bar Member Posts: 91
    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?
    pylxw6fs08a1.png
  • waitwait Member Posts: 53
    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#latest
  • kefkef Member Posts: 7
    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 :-)

    /kef
  • foo_barfoo_bar Member Posts: 91
    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.

  • kefkef Member Posts: 7
    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.
  • kefkef Member Posts: 7
    Hi @foo_bar ,

    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 :-)
Sign In or Register to comment.