GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

In a world of connected systems and compliance-driven automation, businesses often need to call external APIs to fetch authentication tokens, retrieve transaction statuses, or communicate with government gateways. Traditionally, this required custom development, but not anymore.

In this article, we’ll show how to:

  • Trigger an Azure Logic App from Dynamics 365 Finance
  • Send a request with custom headers and body using Electronic Reporting (ER)
  • Use Electronic Messaging (EM) to orchestrate the request-response lifecycle
  • Parse and save the API response directly into D365 tables, no custom code

🛠️ Step-by-Step Setup of Azure Logic App for Access Token Request

🔁 Scenario:

We want Dynamics 365 to send a secure API request to this Logic App to get an access token. The Logic App will:

  • Check if the request contains correct security headers
  • If yes, return a sample token response
  • If no, return an error message

✅ Step 1: When an HTTP request is received

📍 Purpose:
This is the trigger that starts the Logic App. It waits for a request from an external system (like D365 or Postman).

💡 Why it’s needed:
You need an endpoint that Dynamics 365 can “call” to request a token.

image-185 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

✅ Step 2: Condition Check – Validate Headers

📍 Purpose:
These checks whether the incoming request includes all four mandatory headers:

Header NameExpected Value
Content-Typeapplication/x-www-form-urlencoded
x-api-authorizationbearer
x-signatureD365-Generated-Signature

💡 Why it’s needed:
To make sure the request is coming from a trusted source and has all required fields for security and business logic.

image-187 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

✅ Step 3 (If Headers Are Valid): Return Token Response

📍 Purpose:
If all headers match, the Logic App will respond with a predefined JSON token:

{

    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJh...",

    "scope": "api.read api.write",

    "token_type": "Bearer",

    "expires_in": 3600

}

💡 Why it’s needed:
This token can now be used by Dynamics 365 in further API requests, like submitting invoices or querying third-party services.

image-184 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

❌ Step 4 (If Headers Are Missing or Wrong): Return Error Response

📍 Purpose:
If any header is missing or incorrect, the Logic App returns an error like:

{

  "error": "Invalid request headers"

}

💡 Why it’s needed:
This prevents unauthorized or incorrect calls from proceeding.

image-189 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Final Logic app

image-7 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

🧪 Step-by-Step Testing with Postman – Validate Logic App Response

After setting up your Azure Logic App it’s time to test it using Postman. We’ll simulate two scenarios:

✅ Scenario 1: Valid Headers – Return Token Response

This test checks if the Logic App returns a token when the correct headers are provided.

🔁 Request Setup in Postman:

  • Method: POST
  • URL: Paste your Logic App HTTP endpoint URL

🔐 Request Headers:

Header NameValue
Content-Typeapplication/x-www-form-urlencoded
x-api-authorizationbearer
x-signatureD365-Generated-Signature
image-6 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

📝 Body (raw text):

grant_type=Mutual

image-5 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

📥 Expected Response:

{

    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJh...",

    "scope": "api.read api.write",

    "token_type": "Bearer",

    "expires_in": 3600

}

This confirms that the Logic App validated the headers and returned the correct token.

image-9 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

❌ Scenario 2: Invalid Headers – Return Error Response

This test checks if the Logic App rejects the request when headers are missing or wrong.

🔁 Change One Header:

For example, change x-api-authorization to:

x-api-authorization: Bearer123  ← Incorrect value

📥 Expected Error Response:

{

  "error": "Invalid request headers"

}

🔒 This confirms the Logic App’s security layer is working as expected.

image-8 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

⚙️ Integrating Logic App with D365FSCM Using ER and Electronic Messaging

In this section, we’ll walk through how to configure Dynamics 365 FSCM to trigger your Logic App, receive a JSON token response, and store that response in your system — all using standard Electronic Reporting (ER) and Electronic Messaging (EM), with no X++ code.

We’ll split it into 7 clear steps:


Prerequisite

Create 3 custom fields with the same name. These fields have been used to capture Logic app response

AccessToken

image-188 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

AccessTokenDateTime

image-194 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

ATValidityPeriod

image-186 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

These fields are added on Web application screen

image-190 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

1. ER Formats

Download and Import all configuration in your environment – Download ER Configurations

Export Configuration

Defines the JSON request (headers, body) that D365FSCM will send to the Logic App. Following configurations are in above location so make sure you import them

image-211 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Import Configuration

Defines how the JSON response from the Logic App will be read and mapped into D365 tables. Following configurations are in above location so make sure you import them

image-191 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

2. Electronic Message Statuses

Tracks each stage of the process. Helps monitor progress and troubleshoot errors.

Message statusDescriptionResponse typeMessage item statusAllow delete
Error_Request_FormatCommon error in request bodyTechnical errorYes
Error_Response_ImportFailed to read/import API responseTechnical errorYes
Error_Sending_RequestError while sending token requestTechnical errorYes
Token_Request_CreatedMessage created but not sent yetSuccessfully executedYes
Token_Request_SentRequest sent to API successfullySuccessfully executedNo
Token_Response_ReceivedResponse file has been receivedSuccessfully executedNo
Token_Saved_To_DatabaseToken stored successfullySuccessfully executedNo
image-189 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

3. Electronic Message Processing Actions

Breaks the process into smaller tasks: create the message, generate request, call the Logic App, and import the response.

Electronic Message ActionsPurpose / Description
Create Token RequestStep to create the message
Generate Request BodyStep to build the JSON body
Import Token ResponseReads and saves response data
Send Request to APICalls Logic App endpoint (Web Service Action)
image-198 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-202 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-210 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-212-1024x455 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

4. Electronic Message Processing (Pipeline)

The full execution pipeline – defines the sequence of actions from start to finish so the process runs in the right order.

ActionDescriptionRun separatelyAction typeInitial message statusesResult message statusesUse parameters
Create Token RequestStep to create the messageNoCreate messageToken_Request_CreatedNo
Generate Request BodyStep to build the JSON bodyNoElectronic reporting export messageToken_Request_CreatedError_Sending_Request; Token_Request_SentNo
Send Request to APICalls Logic App endpoint (Web Service Action)NoWeb serviceToken_Request_SentError_Request_Format; Token_Response_ReceivedNo
Import Token ResponseReads and saves response dataNoElectronic reporting importToken_Response_ReceivedError_Response_Import; Token_Saved_To_DatabaseNo
image-206 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

5. Configure Web Service (Secure connection to Webservices)

Stores the Logic App endpoint and connection details, ensuring secure HTTPS calls from D365FSCM.

image-193 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

6. Web Application (Auth2.0)

Holds credentials and authentication settings (e.g., OAuth 2.0 parameters) needed to communicate with the API securely.

image-207 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Add Web applications supplementary headers

HeaderDescriptionValue
x-api-authorizationbearerbearer
x-signatureD365-Generated-SignatureD365-Generated-Signature
image-197 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

7. Electronic Message (Container)

The working record for each API call – stores request, response, logs, and attachments for audit and troubleshooting.

image-207 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

🧪 Step-by-Step Testing with Electronic Message – Validate Logic App Response

Run the pipeline inside D365FSCM to send a request to the Logic App, retrieve the JSON token, and confirm it’s stored in your web application table. If the Logic App returns an error (e.g., wrong headers), the EM log will capture it for review.

Create New

Creates a new electronic message record to start a fresh process

image-198 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-201 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-195 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Generate Report

Runs the linked ER export format to build the request file or data payload (JSON) that will be sent out.

image-204 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-189 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-192 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-196 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Send Report

Sends the generated request file to the connected web service or endpoint (Logic Apps in this case).

image-199 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-204 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-208 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-200 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Verify Logic app trigger

Check Logic app run. Above access token received from Logic app

image-203 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-209 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

Import Response

Runs the linked ER import format to read the incoming response file from the web service and store the results in D365 tables for tracking or further processing.

image-208 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-207 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-203 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-197 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting
image-205 GS518 – Integrating External APIs with Logic Apps and Electronic Reporting

🧪 How It All Works at Runtime

  1. User runs processing from the EM workspace
  2. Request body and headers are generated by ER
  3. Logic App is triggered, returns response JSON
  4. Response is parsed, token stored in D365
  5. Logs are created, status is updated, attachments stored

🧠 Best Practices & Recommendations

AreaBest Practice
SecuritySecure Logic App with OAuth or header-based key
Token expiryUse expires_in to trigger future token refresh
ReusabilityCentralize token storage in EMWebApplication table
EnvironmentsUse parameterized Logic App URLs per environment
Audit trailAlways write logs to BusinessDocumentExecutionResultLog or attachments

🧾 Real-World Scenarios

  • Fetch access tokens from customs or banking APIs
  • Submit invoice batches to eInvoicing platforms with signed headers
  • Call tax rate services or validation engines via Logic Apps
  • Push data into external audit or fraud detection APIs

📘 Coming Up Next

In GS519 – Managing Errors, Logs, and Submission History in Globalization Studio, we’ll explore how to track, troubleshoot, and resolve issues that arise during document submission—using real examples like Spain’s FACe and SII submissions.
You’ll learn how to:

  • Read pipeline logs and error messages
  • Analyze submission results and trace failures
  • Export logs for audit purposes
  • Retry or reprocess failed transactions

📖 Continue reading: GS519 – Logs and Troubleshooting

🔍 View Full Article in PDF

GS518-1

Share this content:

I am Yogeshkumar Patel, a Microsoft Certified Solution Architect and ERP Systems Manager with expertise in Dynamics 365 Finance & Supply Chain, Power Platform, AI, and Azure solutions. With over six years of experience, I have successfully led enterprise-level ERP implementations, AI-driven automation projects, and cloud migrations to optimise business operations. Holding a Master’s degree from the University of Bedfordshire, I specialise in integrating AI with business processes, streamlining supply chains, and enhancing decision-making with Power BI and automation workflows. Passionate about knowledge sharing and innovation, I created AI-Powered365 to provide practical insights and solutions for businesses and professionals navigating digital transformation. 📩 Let’s Connect: LinkedIn | Email 🚀

Post Comment

Table of Content