NAV 2018 API - Complex Types

wait
Member Posts: 53
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

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

3
Best Answers
Answers
-
Nice! Can you do this in AL?0
-
Thanks for the post,it's great!
Maybe you can help me,i created OData EDM Type like this,but after APIs integrate i can't see complexType i added in metadata and this can be the reason why i cant generate complexType in JSON.
Any idea how to update metadata? Thanks in advance!0 -
> @Milek212mm said:
> Thanks for the post,it's great!Maybe you can help me,i created OData EDM Type like this,but after APIs integrate i can't see complexType i added in metadata and this can be the reason why i cant generate complexType in JSON.
> Any idea how to update metadata? Thanks in advance!
Hi Milek212mm, If you followed all the steps you should see the metadata for the complex type so its difficult to say why its not working for you.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