RSS

Monthly Archives: November 2022

Business Central: Can’t find/get invoices with API

We had a scenario were we did an OnPrem installation for a customer (BC 19.x). We had set up three NST, one for web clients, one for job queue and one for API. We had a Cronus database as a base were we created a new empty company besides the cronus company.
When we wanted to get posted invoices via API we couldn’t find any even though we had posted several invoices(!). First we thought something was wrong with the API NST but we could reach other companies and it became even weirder when we tried to access invoices in the cronus company, then it worked!

So why the hell did it work against the Cronus company in the same database with the same NST BUT NOT for our newly created company!? 🤔

First you should know that when you try to get invoices via API it doesn’t access them from standard Sales Invoice Header/Lines table. Instead these invoices are copied to a mirror table where it stores both posted AND unposted invoices. So every time you post an invoice it will be stored in the mirror table that is used for API communication.

Ok, so we compared the mirror table (“Sales Invoice Entity Aggregate”) in our new company with the one in the Cronus company. There were data in the Cronus company but no data in the new one. Why is that?

Eventually we found the learn page for it.

Great there is button we can run to fill the tables the API-setup to fill the mirror tables ! 😁 We ran, it and then we could FINALLY reach the invoices, BUT why does not new posted invoices get copied there automatically? 🤔

It took some debugging until we found out why. In Codeunit “Sales Invoice Aggregator” is a subscriber event that subscribes on when Posted Invoices are being inserted and then copies them to the mirror table BUT, if AND only if the API is enabled.

But we have enabled it on our API NST… Lets look closer at the IsApiEnabled function:

It is getting the “Enable API Services” setting from the NST.

Remember I said that we generally have three NST, one for web clients, one for job queues and one for API. This means that if we post invoices on the web client NST and don’t have “Enable API Services” on that NST it won’t copy those records to the mirror tables that the API accesses.

Conclusion:
Even though we have a dedicated NST for API we still have to enable “Enable API Services” for all the NST:s that generate data that should be copied API mirror tables. But it is enought to only expose one NST via the firewall 😉

 
Leave a comment

Posted by on 2022-11-19 in Okategoriserade

 

Tags: , ,

 
Stefan Maroń

Dynamics 365 Business Central

James Pearson

Thoughts about Dynamics 365 Business Central, Git, Azure DevOps, PowerShell, Automated Testing, Visual Studio Code...and maybe some other stuff

Roberto Stefanetti BLOG

MVP & MCT Business Central, Powershell, Azure, SQL Server

JoeBrown

DevOps starts with culture!

Comments for DevOps ABCs Blog

Reflections from the ERP field

DevOps ABCs Blog

Reflections from the ERP field

Dynamics 365 Business Central for Partners

Reflections from the ERP field

Freddys blog

Learn something new... - then Teach someone!

Stefano Demiliani Technical Blog

Reflections from the ERP field

David Worthington's NAV Performance Blog

Micosoft Dynamics NAV Performance Testing & Optimization

Freddys Blog

Reflections from the ERP field

Marije Brummel Blog | Business Central, Azure and more...

Design Patterns, Performance, Clean Code

Vjeko.com

Ideas in the cloud

Goprowe AB

Reflections from the ERP field

ArcherPoint

Reflections from the ERP field

The NAV Viking´s Blog

- Sharing my experience in the Dynamics NAV world

Comments for

Reflections from the ERP field

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav / D365 Business Central

Navision-Girl.Com

Reflections from the ERP field