How to access/display Business Central data directly in Power Apps without using Dataverse and standard Power Platform connector – Call HTTP Request via Power Automate

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share an interesting topic, how to access/display Business Central data directly in Power Apps without using Dataverse and standard Power Platform connector.
As you might know, if you want to connect Business Central data from Power Apps, there are generally two ways.

1. Using standard Power Platform connector: This connection method accesses data through BC’s APIs, so it is updated in real time. Here is a simple example:

More details: Connecting to Your Business Central Data to Build a Business App Using Power Apps

2. Using Dataverse: This method does not directly access BC data, but goes through an intermediate layer, integrating Dataverse and BC first, and then accessing the data in Dataverse from Power Apps.
So, we need to setup a connection to Dataverse first.

More details:
1. Dynamics 365 Sales and Business Central integration setup (Set up a connection to Dataverse and Set up a connection to Dynamics 365 Sales)
2. Dynamics 365 Business Central: Customizing an Integration with Microsoft Dataverse (Integrate custom tables)

For example,

Please note that this method is not real-time, on a standard connection it updates every 30 minutes.

Both methods are feasible according to user needs. But it should be noted here that the first method, because it accesses BC through a standard connector, requires the user to have a BC license. The second method uses Dataverse, which requires the purchase of a Dataverse license, such as Power Apps Premium. Otherwise, the capacity of the Dataverse is 0G. (Sorry I’m not an expert on licensing, please let me know if there are any issues)

In this post, I would like to share the third way, call HTTP Request via Power Automate and then get BC data as Response.

We have discussed Using OAuth 2.0 to connect Business Central APIs and Web Services in Power Automate – OAuth in HTTP action before. The authentication part is the same and will not be repeated this time. You need to obtain the Client ID and Client Secret from App Registration in the Azure Portal. For example,

Client ID: b4fe1687-f1ab-4bfa-b494-0e2236ed50bd

Client Secret: huL8Q~edsQZ4pwyxka3f7.WUkoKNcPuqlOXv0bww

Okay, let’s get started right away.

1. Choose + Create to create a new flow in Power Automate.

Choose Skip.

Then an empty flow is created.

PS: Disable New designer in the upper right corner to return to the previous designer. In this post, I shared it on the previous designer and the new one is the same.

First, give the flow a name.
For example, Business Central Customer List (This will be displayed in Power Apps)

2. Select Power Apps -> When Power Apps calls a flow (V2) as the trigger.

3. Choose + New step, then search for HTTP to add it.

4. Add the following settings.

MethodPOST

URlhttps://login.microsoftonline.com/7e47da45-7f7d-448a-bd3d-1f4aa2ec8f62/oauth2/v2.0/token (Access Token URL in Postman)

HeadersContent-Type : application/x-www-form-urlencoded

Bodygrant_type=client_credentials&client_id=b4fe1687-f1ab-4bfa-b494-0e2236ed50bd&client_secret=huL8Q~edsQZ4pwyxka3f7.WUkoKNcPuqlOXv0bww&scope=https://api.businesscentral.dynamics.com/.default (Note it’s just one string, not JSON format, and the contents are the same as the set in Postman, Grant Type, Client ID, Client Secretand Scope)

To make it easier to understand, let’s rename this step, for example, Get New Access Token

PS: At this step, we have been able to test whether the Token can be obtained properly.

Save -> Test

Manually -> Test

Run flow

Done.

Your flow run successfully.

You can find access token in Body.

Let’s continue. For ease of use, in the next step we will get the access token from the the body of the previous HTTP action.

5. Choose + New step, then search for Compose to add it.

Enter the following formula in Inputs. ‘Get_New_Access_Token’ is the name of the previous HTTP action with the space replaced by the underscore.

@outputs('Get_New_Access_Token').body.access_token

This can be confirmed in the Peek code.

We can test it again. And it looks good.

6. Use this Access Token to access BC’s API.

Choose + New step, then search for HTTP to add it.

As run in Postman below, we use Get Method to get the information of customers in BC.
Test Endpoint:

https://api.businesscentral.dynamics.com/v2.0/7e47da45-7f7d-448a-bd3d-1f4aa2ec8f62/Sandbox251/api/v2.0/companies(fd0d0d51-099b-ef11-8a6d-002248e7a2bb)/customers

Add the following settings.

Method: Get

URl: https://api.businesscentral.dynamics.com/v2.0/7e47da45-7f7d-448a-bd3d-1f4aa2ec8f62/Sandbox251/api/v2.0/companies(fd0d0d51-099b-ef11-8a6d-002248e7a2bb)/customers

Headers: Authorization: Bearer Outputs (Please note that there is a space in the middle.)

Outputs need to be selected from Dynamic Content.

Test again:

You can choose Show raw outputs to see more info.

The above is the process of using OAuth 2.0 to connect Business Central APIs. Since we need to display the data in Power Apps in a list format, some processing is required. There are many ways to do this, I will share a simpler one.

Click New step, search for Parse Json, and click on it.

In Conent, select the Body of the Http step.

For Schema, you can also enter it manually, but if the json file is very complex, choose Generate from sample

Sample can be obtained from the HTTP Body. (You can also get it from Postman’s Body)

Paste the json value and click Done.

Done.

Click New step, search for Select, and click on it.

In From, select the value of the Parse JSON step.

In Map, enter header on the left side and select the mapped value of Parse JSON Step on the right side. These fields are the fields in the API.
PS: Dynamics 365 Business Central: Can we extend standard APIs? – Download Standard Source Code for APIs

Peek code:

Test:

We need to send back the HTTP response to power apps. Next is the last step. Click New step, search for Response, and click on it.

Status Code: 200 is automatically filled in. In Body, select the Output of the Select step.

Click Show advanced options

As with the Parse Json step, we need to generate a schema.

Sample can be obtained from the Select Body.

That’s all, finally you can test it.

Then let’s open Power Apps.

Choose + Create to create a new app.

Blank app

Blank canvas app -> Create

Enter a app name, then choose Create.

Skip the welcome page.

Choose Power Automate

Then choose Add flow

You can find the flow you just created in Power Automate and click on it.

It will be added to In your app.

Then let’s add two buttons.

One is Get Data and the other is Clear Data.

We can store data in a collection. So, add the following formula to OnSelect property of the action.

Get Data:

ClearCollect(CustomerList,BusinessCentralCustomerList.Run());

Clear Data:

Clear(CustomerList)

Then we need to display the data. This time I use Layout -> Data table.

Then choose Data -> CustomerList (This is the name of the collection created in the formula)

Choose Fields -> Add field, then select the fields you want to display in order.

Choose Add.

Done.

Test:

Test video: This method is also real-time synchronization.

The biggest benefit of this method is that users without a BC license can also access BC data in Power Apps.
For example, the user below does not have a BC license.

I shared with him the app and flow I had just created.

This user does not have permission to access BC, but can access BC data through Power Apps.

Test video: And this approach does not require Dataverse

Very simple, give it a try!!!😁

END

Hope this will help.

Thanks.

ZHU

コメント

Copied title and URL