Logic App workflow for creating a file in SFTP with exception handling
To create an Azure Logic App workflow that posts HTTP data and saves it as a file in SFTP, with exception handling to send an email upon failure.
Step-by-Step Guide
- Initialize the Logic App
- Navigate to the Azure Portal and select Logic Apps.
- Create a New Logic App and provide the necessary details such as resource group and location.
- Configure the Workflow
- In the Logic App Designer:
- Add an HTTP Trigger:
- Add the “When a HTTP request is received” trigger with “POST” method.
- Request Example:
{ "id": "123", "name": "Estudy247", "email": "estudy24by7@gmail.com" }
- Add SFTP Create File Action Inside a Scope:
- Add a Scope action named “MainScope”.
- Inside this scope, add an “SFTP-SSH – Create file” action.
- Provide the SFTP server details, file path, and set the file content using the body of the HTTP request.
- Example:
{ "id": "123", "name": "Estudy247", "email": "estudy24by7@gmail.com" }
- Add Error Handling Scope:
- Add another Scope action named “ErrorHandlingScope”.
- Configure ErrorHandlingScope to run after the main scope fails or times out. Click on the ellipsis (three dots) on this scope > “Configure run after” > Set it to run after MainScope has failed and has timed out.
- Capture Error Message:
- Inside ErrorHandlingScope, add a “Filter array” action.
- The following JSON code to validate if “MainScope” is failed:
{ "type": "Query", "inputs": { "from": "@result('MainScope')", "where": "@equals(item()['status'],'Failed')" } }
- Send Email on Error:
- Inside ErrorHandlingScope, add an “Send email (V2)” action (or another email service).
- Configure the email action with recipient details, a subject, and the error message.
- In the Logic App Designer:
Here's how Logic App should look:

You can download the logic app template from the estudy247 GitHub repository – la-test-sftp-05
