Azure Logic Apps: How to Post Multipart and Form-data

Geethu Suresh
Version 1
Published in
4 min readOct 14, 2021
Photo by Piero Nigro on Unsplash

Introduction

This article describes how to send multipart and form data to HTTP Post API via Azure Logic Apps.

Azure Logic Apps is a cloud-based service that allows users to create and run automated workflows across multiple apps, services, data, etc.

Multipart requests combine sets of data into a single body, separated by boundaries. Mostly used when the user will have to upload a file through a form.

Figure 1: Architecture.
  1. An email arrives in an outlook mailbox (we use a shared mailbox here).
  2. The Logic App O365 triggers and the email is processed.
  3. The Logic App fetches the attachment in the email.
  4. The attachment is sent to the API through HTTP Post

More related: Why choose Version 1 as your Microsoft Service Partner?

  1. An Azure subscription.
  2. An API endpoint that accepts multipart/form-data.
  3. A mailbox from a service that works with Azure Logic Apps, such as Office 365 Outlook or Outlook.com. We are using a shared mailbox here.

Procedure

Create a logic app resource in Azure

Step 1: Navigate to the Azure portal.

Figure 2: Search Logic app in Azure Portal

Step 2: In the search box on top, search for “logic apps”, and select Logic apps.

Step 3: Click on “Add” to create a Logic app.

Figure 3: Add Logic app

Step 4: On the Create Logic App pane-

· Select the Azure subscription, resource group (create new if needed).

· Enter the name for the logic app and choose your region.

· Click on “Review + Create”.

· Confirm the details and select Create.

· Once deployed, select “Go to resource”.

Figure 4: Create Logic App

Create the workflow

Step 1: In the logic app resource -

· Select “Workflows”. Click on “Add”.

· Enter the workflow name and choose the State type as “Stateful”.

· Click on “Create”.

Figure 5: Create Workflow

Step 2: Navigate to the created workflow and click on “Designer”.

Step 3: Add the Office365 Trigger-

· Click on “Choose an operation”.

· Search and add “When a new email arrives in a shared mailbox” trigger under the “Azure” tab.

Figure 6: Add Trigger

· Set the mailbox address and “Include Attachments” to “Yes”.

Figure 7: Trigger details

Step 3: Add an Action: Search for “Condition” and add it to check whether attachments are present. Set “Has Attachments” is equal to true.

Figure 8: Condition

Set “Has Attachments” is equal to true as the condition check.

Figure 9: Condition details

Step 4: Add an Action: HTTP Post.

· Under the true section of the condition, click on the “+” button and add an action.

· Search for “HTTP” and add “HTTP” action.

Figure 10: HTTP Action

· Enter the details of the request. Set the URI to your post endpoint.

Figure 11: POST request details
"body": {
"$content-type": "multipart/form-data",
"$multipart": [
{
"body": "@items('For_each_attachment')?['contentBytes']",
"headers":
{
"Content-Disposition": "form-data; name=file; filename=\"@{items('For_each_attachment')?['name']}\"",
"Content-Type": "@{items('For_each_attachment')?['contentType']}"
}
}]
}

· Lastly, click on the “Save” button to save your workflow.

Test the workflow

  1. Send an email with an attachment to the configured mailbox.
  2. Go to logic app resource, click on “Overview”.
  3. Check the “Status” of the run under “Run History”.
Figure 12: Run History

About the Author

Geethu Suresh is currently a Microsoft .Net Consultant working for Version 1. Be sure to follow Geethu for more blogs on Innovation.

--

--

Geethu Suresh
Version 1

A software engineer who enjoys meaningful conversations over a cup of coffee!