Deep inserting into nested tables via API involves creating or updating records in multiple related tables in a single API request. This approach is especially useful in scenarios where data structures are complex, involving parent-child relationships.
Deep insert operations streamline data management by allowing developers to send a single payload that includes all related entities, reducing the need for multiple API calls and ensuring data consistency across the nested tables.
In this blog we will see how we can Deep insert for 2 nested tables through API.
The structure of nested tables which we will use today is as below:
Main Table 1 -> Table 2 (Header Table) -> Table 3 (Line Table linked to Table 2)
Item Table -> Extended Text Header -> Extended Text Line.
Firstly, let’s create API page and Listpart pages.
- Create Item API Page and add Part for Extended Text Header and Extended Text Line tables as shown below:
- Create Extended Text Header ListPart Page:
- Create Extended Text Line ListPart Page:
Now, Let’s create ITEM in Business Central along with Extended Text Header and Line in it using POST API method.
Notice in below API, we need to write both Part’s EntitySetName by separating it with “,” to perform transactions.
API: https://api.businesscentral.dynamics.com/v2.0/82a8b85e-ea76-48f6-80a3-21b13efa3a94/Sandbox/api/MBS/mbsgroup/v2.0/companies(c381e6b6-b3d3-ee11-904f-6045bdac9aed)/itemextendedapi?$expand=extendedtextheaders,extendedtextLines
Body: Add Body data in below mentioned format to insert data in Nested tables (Item Table -> Extended Text Header -> Extended Text Line).
Once we post API, Item will be created in Business Central along with Nested tables Extended Header and Extended Line. Please refer below screenshots of Business Central.
If you’re curious about how we can assist you in reaching your goals, don’t hesitate to get in touch. Our dedicated team is ready to provide support every step of the way.
Let’s turn your vision into reality together!