Using Bearer Token to Call Recurring Integration of D365FnO Using Logic Apps
x
Introduction
In this article, we will walk through the process of using a bearer token to authenticate recurring integration URIs for interacting with Dynamics 365 Finance and Operations (D365FnO). We will demonstrate how to set up a Logic App in Azure to handle this integration, using an XML-based input to feed data into D365FnO.
Prerequisites
- Azure Subscription: Access to create Logic Apps.
- D365FnO Environment: With enqueuing URL set up.
- App Registration: In Azure AD to get Client ID and Client Secret.
- Azure Key Vault (Optional): For securely storing Client ID and Client Secret.
Step-by-Step Guide
Step 1: Set Up Logic App in Azure
- Create Logic App: Navigate to the Azure portal, and create a new Logic App.
- Open Logic Apps Designer: Once created, open the Logic Apps Designer.
Step 2: Declare a Token Variable
- Initialize Variable: Add an action to initialize a variable called
token
.- Type:
String
- Name:
token
- Type:
Step 3: Generate Bearer Token
HTTP POST Request:
- Add an HTTP action to perform a POST request to generate the token.
- URI:
https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
- Header:
Content-type
:application/x-www-form-urlencoded
- Body: Use the following format:client_id=<Client ID>&client_secret=<Client Secret>&grant_type=client_credentials&scope=https://<base URL of D365FnO>/.default
- Example Body:client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials&scope=https://your-d365-url/.default
Note: To avoid exposing sensitive information, store
client_id
andclient_secret
in Azure Key Vault and fetch them in the Logic App.
Step 4: Parse the JSON Response
- Parse JSON:
- Add an action to parse the JSON response from the token generation request.
- Use the output from the previous HTTP action.
- Schema:{ "type": "object", "properties": { "access_token": { "type": "string" } } }
Step 5: Set the Bearer Token
- Set Variable:
- Add an action to set the
token
variable. - Value:
@body('Parse_JSON')?['access_token']
- Add an action to set the
Step 6: Call Enqueue/Dequeue URLs
- HTTP Request:
- Add an HTTP action to call the D365FnO enqueue/dequeue URL.
- URI: Enqueue/Dequeue URL of your D365FnO environment.
- Header:
Authorization
:Bearer @{variables('token')}
- Body: Pass the XML content you want to send to D365FnO.
Step 7: Optional - Loop for Execution Completion
- Loop:
- Add a loop to wait for execution completion or handle errors.
- Inside the loop, you can add conditions to check the status of the previous request and repeat if necessary.
Example Logic App Workflow
- Initialize Variable:
token
(String) - HTTP POST: Generate Bearer Token
- Parse JSON: Extract
access_token
- Set Variable: Set
token
variable toaccess_token
- HTTP Request: Call Enqueue/Dequeue URL with Bearer Token
Summary
By following these steps, you can set up a Logic App to use a bearer token for authenticating and interacting with Dynamics 365 Finance and Operations. This setup ensures secure and efficient data integration, allowing you to automate data imports and updates in D365FnO.
This approach not only secures your API calls but also simplifies the process of managing and automating recurring integrations with D365FnO. Happy integrating! 😊
About Our Team
Our team is composed of software development and analysis experts who have worked both domestically and internationally:
- Nghia Song (Mr.) - Technical Architect. With over 6 years of experience in implementing ERP and integration projects.
- Jone Nguyen (Mr.) - Senior Technical Consultant. With practical experience in 25 E-invoice projects with software systems of businesses both domestically and internationally.
- Victor (Mr.) - Senior Project Manager.With over 12 years of specialized experience in Dynamics 365 Fno.
- Lisa Doan (Ms.) – Finance Consultant. A consultant specializing in accounting on Dynamics 365 FO and consolidated accounting systems.
No comments:
Post a Comment