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
    1. Navigate to the Azure Portal and select Logic Apps.
    2. Create a New Logic App and provide the necessary details such as resource group and location.
  • Configure the Workflow
    1. 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"
        }
    2. 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"
        }
    3. 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.
    4. 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')"
        }
        }
    5. 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.
Here's how Logic App should look:
estudy247-la-test-sftp-05

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

Post a comment

Leave a Comment

Scroll to Top