Trigger A Fabric Notebook Through The API

Trigger A Fabric Notebook Through The API

When you want to schedule the export of bc2adls (Bertverbeek4PS/bc2adls) you also must schedule the export of the Fabric Notebook after the export from Business Central to Microsoft Fabric is finished.
See also my blogpost in the past:
BC2ADLS: MS Fabric enabled part 2 – Discover Microsoft Business Central (bertverbeek.nl)

But now there is an API available to trigger the notebook! In that case when you finished the bc2adls export you can trigger the notebook directly. So you have almost a near real time copy of your records.

Notebook API

Currently it is possible to run a notebook on-demand:
Manage and execute Fabric notebooks with public APIs – Microsoft Fabric | Microsoft Learn
You can call the notebook with the following API request:

POST https://api.fabric.microsoft.com/v1/workspaces/4f8a8c2e-86b0-405d-a7e5-a4c84214f1dd/items/bd4ac8cf-67bf-4ae1-a4cb-321844f8d019/jobs/instances?jobType=RunNotebook

The GUID 4f8a8c2e-86b0-405d-a7e5-a4c84214f1dd is your workspace GUID and bd4ac8cf-67bf-4ae1-a4cb-321844f8d019 is the notebook GUID.
When you navigate to the notebook inside MS Fabric you can extract it from the URL:

In the body you don’t have to declare anything:

{
    "executionData": {       
    }
}

When you to the POST request and look inside MS Fabric you can see that it is executed:

NB: to run the notebook you need to do it under a real user. It doesn’t allow you to it with the client credentials flow yet. It will say that he accepted it. But the Notebook will not run.
It only will run with the Authorization flow code and Password credentials.

Business Event inside bc2adls

But now you need to receive a notification that the bc2adls export is finished. Lucky, we have since BC22 External Business Events. And in the bc2adls there is an External Business Event when the export is finished:

So in that way we can use Power Automate or Logic app (or any other app) to kick of the Fabric notebook straight away when bc2adls is finished.

Power Automate Flow

When you use Power Automate you can use also the trigger “When a business event occurs (V3)”:

And select the event “Export is finished”.

When that is happen you can kick of the API of the Fabric Notebook:

And when you have done this your notebook will start directly when the export is finished. So i that case you have a real near time copy of your data in Microsoft Fabric.

NB: I have stored the Client Secret and password directly in the Power Automate flow because of simplicity for this blog. But please stores those values safely into a key vault for example.

An example of the Power Automate flow you can download here:
Power Automate Package

2 COMMENTS

Lars Hammer

Splendid work, Bert
We are definitely taking this into use, so we can trigger the Consolidation notebook automatically, when the bc2adlse has exported the data from Business Central.
One good learning from this is that the call must be made using a real user. We have been struggling trying to use client credentials (service principal), but could not get that to work.

Greg Long

Bert – thanks for including this in a recent release of the bc2adls.
My question relates to multi-company exports. If I’m exporting the BC data from multiple BC companies simultaneously, am I able to apply the Power Automate to a single BC company “business event”? Or will the Power Automate Flow trigger after each of my BC company’s exports complete?

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.