cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JesusF-MSFT
Microsoft
Microsoft

[Walkthrough] How to use Invoke Web Service with multipart/form-data in Power Automate Desktop

Summary 

A common requirement when sending/receiving data is to use an existing service. However, calling an external API may require a specific configuration. In this post I will explain how to configure Power Automate Desktop to use a REST API as service using the Invoke Web Service action.

 

Prerequisites 

  1. Visual Studio 2019 with .NET cross-platform development workload 
  2. Postman 
  3. Power Automate Desktop 

 

Requirements 

The requirement for this walkthrough will be edit a profile information by submitting data using the following: 

URL 

[base-url]/profile/info 

Method 

POST 

Content type 

multipart/form-data 

Form data 

name, surname

 

Configuring the API

You can skip this step if the API that will be consumed is already configured. 

The first step is to make sure that the API method is configured correctly to allow receiving data into chunks. In ASP.NET Core this is done by adding the Consumes attribute to the publicly facing method, like so: 

 

[ApiController] 
[Route("[controller]")] 
public class ProfileController : ControllerBase 
{ 
	[HttpPost] 
	[Consumes("multipart/form-data")] 
	[Route("info")] 
	public async Task<IActionResult> PostInfoAsync() 
	{ 
		// Do work 
		return Ok(); 
	} 
} 

 

 

Testing the API method using Postman

You can make sure that you have configured the method correctly with Postman by setting the body to form-data and providing a list of keys and their corresponding values. This will useful later when you need to configure the Invoke Web Service action in Power Automate Desktop.

 JesusFMSFT_0-1625580469109.png

 

After you have provided the data, click on Send to submit the request to the service. You should receive a 200 OK response from the service if everything was configured correctly.  

Postman provides snippets of all kinds, but the one that you are interested in is HTTP. 

JesusFMSFT_1-1625580469106.png

 

 As you noticed, the snippet not only specifies in Content-Type the type of data that you want to submit, but also a boundary parameter. You need to include this as is in the Invoke Web Service action to work as expected. 

 

Calling API method using Power Automate Desktop 

After making sure that the API method works, the last step is to simply configure the action in Power Automate Desktop like so: 

 

JesusFMSFT_2-1625580469115.png

 

Encoding request body

One important step is to make sure that the option to encode the request body matches the configuration at the receiving end. 

Encoding a request body means that Power Automate Desktop will encode the entire body, including query-string values. If characters such as blanks and punctuation are passed in an HTTP stream, they might be misinterpreted at the receiving end. 

Enabling the Encode request body option in the Advanced section converts characters that are not allowed in a URL into character-entity equivalents. For example, when the characters < and > are embedded in a block of text to be transmitted, they are encoded as %3c and %3e respectively. 

JesusFMSFT_3-1625580469112.png

 

 

3 REPLIES 3
yoko2020
Resolver II
Resolver II

Show us example to upload files using invoke web service.

tkuehara
Solution Specialist
Solution Specialist

Hi @yoko2020 

 

I guess this is gonna depend on the API you're currently using but here is an example from a project I'm working at:

First, I send a request to signalize to the API that I'm gonna send a file to it. If successful, the API returns the URL I must send the file to:

tkuehara_0-1625607316067.png

Second, I upload the file to the URL using curl:

tkuehara_1-1625607443245.png

tkuehara_2-1625607509940.png

 

If using curl i can do that.

What i ask is uploading files pure using only action  invoke web service.

I am just hoping they can integrate this feature in that action.

No need to use another solution when dealing with upload files.

 

 

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,440)