Using Bearer Token to Call Recurring Integration of D365FnO Using Logic Apps - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam


Monday, June 24, 2024

Using Bearer Token to Call Recurring Integration of D365FnO Using Logic Apps

  Using Bearer Token to Call Recurring Integration of D365FnO Using Logic Apps


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.


  • 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

  1. Create Logic App: Navigate to the Azure portal, and create a new Logic App.
  2. Open Logic Apps Designer: Once created, open the Logic Apps Designer.

Step 2: Declare a Token Variable

  1. Initialize Variable: Add an action to initialize a variable called token.
    • Type: String
    • Name: token

Step 3: Generate Bearer Token

  1. HTTP POST Request:

    • Add an HTTP action to perform a POST request to generate the token.
    • URI:{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:

    Note: To avoid exposing sensitive information, store client_id and client_secret in Azure Key Vault and fetch them in the Logic App.

Step 4: Parse the JSON Response

  1. 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

  1. Set Variable:
    • Add an action to set the token variable.
    • Value: @body('Parse_JSON')?['access_token']

Step 6: Call Enqueue/Dequeue URLs

  1. 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

  1. 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

  1. Initialize Variable: token (String)
  2. HTTP POST: Generate Bearer Token
  3. Parse JSON: Extract access_token
  4. Set Variable: Set token variable to access_token
  5. HTTP Request: Call Enqueue/Dequeue URL with Bearer Token


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.

Song Thành Nghĩa                                                 
Microsoft Dynamics 365 Technical Architect
Mobile/WA: +356 7748 2386 | Web:
Zalo: +84 967 324 794 | Mail:

No comments:

Post a Comment