Using the poweautomate we can use the BC OAuth2.0 and use that token for futher use in the samel powerautomate flow. in the below example I am creating a Incoming document by getting the email attachment, I am not going through the full powerautomate instead I will show you how you can use the OAuth2.0, generate the Token and use that token as Bearer authentication.

Post Method https://login.microsoftonline.com/{TenantID}/oauth2/v2.0/token

Body (Plain Text)

grant_type=client_credentials
&username={username}
&client_id={Client ID}
&scope=https://api.businesscentral.dynamics.com/.default
&client_secret={Client_Secret_value}

&username={username} – must be as a User in Business Central

&client_id={Client ID} – you can get it when you do the App registration in Azure Portal

&client_secret={Client_Secret_value} -you can get it when you do the App registration in Azure Portal

We will use about Token generator in Power Automate.

Initialize a variable.

PowerAutomate

Now to generate the token, we will add a action of Http type.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now we will parse that Http request to get the Generated token by using of Action Data Operation.

 

 

 

 

 

 

 

 

 

 

 

You can use the Generate from sample button, and paste the whole response you get when you run the post request to generate the token.

for Example.

{
“token_type”: “Bearer”,
“expires_in”: 3599,
“ext_expires_in”: 3599,
“access_token”: “eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSIsImtpZCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSJ9.eyJhdWQiOiJodHRwczovL2FwaS5idXNpbmVzc2NlbnRyYWwuZHluYW1pY3MuY29tIiwo0ynS0gzjUoFJRwDJAH8mcpykbp-mje73UI7ui6Aiwl3h8-kfeco81zyWz3nZgQYH01rgnmzg4eSmvo1qylhL_sjH5gR4EAcl_5nvIBWyg9gd9OwA2KIIOtALSN4NYq_q0oelluFMbnvCJ-xWNZSMeKzZtMVItnVx8AWUz5ZA8ZgnSbauwnuukOhHOuVMg5igOcvVm2IXMLif7fqPG0Qakg93bYw”
}

Now we will set the variable’s value which we had initialize in the beginning of the generated token.

 

 

 

 

 

 

Now in the final setup, you can use that variable in your actual Post or Get http request to run with Bearer authorization.

 

 

 

 

 

 

 

 

 

 

 

 

 

Most important step:

When you are using grant_type=client_credentials make sure you add that same user in Azure Active directory in Business central and assign the relevant permission.

 

Thanks.