NAV 2018 API - Complex Types

waitwait Posts: 11Member
I really like the new NAV 2018 API feature. The only thing I'm missing is better documentation and too much time has gone into reverse engineer how standard Nav is using this feature and finding out the little thing. The purpose by this post is to hopefully save some other poor programmers a little time. If you see something I'm doing wrong then please correct me.

I'm not going to write how to use basic API or even create your own basic API. I used the following two articles and if you are new to the Nav API I would recommend them to get started

how to create custom apis for business central even from macos

how to obtain data from nav standard apis

To see how standard NAV uses this take a look at codeunit 5468 "Graph Mgt - Complex Type".

First thing we need to do is to create the entity data model for our complex type.

1. Step is to create subscriber for the function ApiSetup in the codeunit Graph Mgt - General Tools (function HandleApiSetup)
2. Step is to create the specification for our complex type (function GetBeerEDM)
3. Step is to create function to Insert or Update the OData Type (function InsertOrUpdateBeer)


When this is ready we need to go into /Departments/Administration/IT Administration/Services and sync the API, this we do by pressing the Intergrate APIs button.


Now when we get the Metadata for our API we will see our complex type there


To use our complex type we simply create JSON object that matches the entity we created earlier. For that we will use the codeunit 5459 "JSON Management"


We will then create page of the type API. We will get the JSON object we created in last step and in the ODateEDMType we put the name of the Entity Data Model we created


Now when we call beers we get our complex type


We can also have array of complex types, then we construct our JSON string as an array and use Collection in the ODateEDMType



and get array of our complex type


Best Answer

  • waitwait Posts: 11
    Accepted Answer
    gmorken wrote: »
    Nice! Can you do this in AL?

    Yes it should be pretty much the same process.


  • gmorkengmorken Posts: 38Member
    Nice! Can you do this in AL?
  • waitwait Posts: 11Member
    Accepted Answer
    gmorken wrote: »
    Nice! Can you do this in AL?

    Yes it should be pretty much the same process.
Sign In or Register to comment.