Invoke REST API from Power Automate Desktop

In this tutorial, we will learn how to Invoke a REST API with Power Automate Desktop. For this demo, we will be using the Muhimbi REST API with the HTTP action and Parse JSON in Flow all while understanding the basics of REST API.

  1. Basics of REST API
  2. Before we begin, please make sure the following prerequisites are in place:
  3. About the Muhimbi Converter Online API
  4. Power Automate Desktop(RPA) solution
Basics of REST API

Before we start exploring the Muhimbi PDF Converter Online REST API, let’s understand the structure of REST API requests which is made up of raw HTTP Method, Endpoint, including Headers, and the Body. Let’s understand each of them in detail

  • HTTP VERBS – HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. The primary or most-commonly-used HTTP verbs or methods are POST, GET, PUT, PATCH, and DELETE.
  • URI\Endpoints – REST APIs use URIs to address resources. For APIs, an endpoint can include a URL of a server or service. Each endpoint is the location from which APIs can access the resources they need to carry out their function.
  • Headers – Headers are an important part of the API request and response as they represent the meta-data associated with the API request and response.
  • Request and Response Body – APIs work using “requests” and “responses”. In our example we will  provide a request body in JSON to the REST API call.

Now that we understand the basic element\structure of REST API requests – Let’s use the Muhimbi REST API call to Convert Documents to PDF.

Before we begin, please make sure the following prerequisites are in place:
  • Power Automate subscription with Flow Plan 1 or Plan 2 .
  • Muhimbi PDF Converter Services Online Free, full or trial subscription (Start trial). Once signed up, and the email address has been confirmed, you will receive an API KEY. 
  • Appropriate privileges to create Power Apps and Power Automate.
  • Working knowledge of both Power Apps and Power Automate.
About the Muhimbi Converter Online API

Muhimbi PDF Converter Online provides the most mature subscription-based PDF Conversion and Document Automation platform in the market. You can use the service to create meeting packs, share documents, watermark and secure sensitive information, make content searchable via OCR, and archive to PDF/A in line with regulatory requirements.

API Reference and Endpoints

For links to the Muhimbi PDF Converter Online reference and a list of the API endpoints, see API Reference and Endpoints.

  • Use the following URL and POST for the REST API call
  • Headers:
    • API_key: Your Muhimbi API Key.
    • Content-Type: application/json
  • Body :
      "use_async_pattern": false,
      "source_file_name": "string",
      "source_file_content": "base64string",
      "output_format": "PDF",
      "fail_on_error": true
Use Async Pattern booleanSet True for long running operation
Source file nameTRUEstringName of the source file including extension
Source file contentTRUEbase64stringContent of the file to convert
SharePoint File objectSharePoint File URLS
Output formatTRUEenumOutput format
Override settings stringOptional settings using Muhimbi’s XML syntax
Template file content byteOptional template file content (e.g. infopath XSN file)
Fail on error booleanFail on error
  • Response:
      "processed_file_content": "base64string",
      "base_file_name": "string",
      "result_code": "Success",
      "result_details": "string"

Now that we know the basics of REST API and also understand the MUHIMBI REST Endpoint lets Invoke REST API from Power Automate Desktop.

From a high level, our Power Automate Desktop solution would look like the screenshot below:

Power Automate Desktop(RPA) solution

Step 1:

Launch the application and select New flow in the console. Enter a name for the Desktop flow, and select Create.

Step 2:

Add the “Get files in folder” action to the Power Automate Desktop designer canvas.

  • Folder: Add the Folder Path to the Folder you want to Convert and click on “Save”

Step 3:

Here, we will use the ‘For each’ loop to loop through multiple files, one at a time.

  • Add the ‘For each‘ action to Power Automate Desktop designer.
  • Value to Iterate: ‘%Files%‘ output of the ‘Get files in folder‘ action.

Step 4:

In Power Automate Desktop you can execute Python, VB, and JavaScript code samples. In this example we will use PowerShell Code to Convert a File to a Base64 string, which we will use in the Invoke Web Service action.

Inside the ‘For each’ loop add the ‘Run PowerShell script‘ action.

[convert]::ToBase64String((Get-Content -path "%CurrentItem%"-Encoding byte))

Step 5:

We will trim whitespace from the beginning and the end our Base64 string.

  • Inside the ‘For each’ loop add the ‘Trim text‘ action.
    • Text to trim:%PowershellOutput% output of ‘Run PowerShell script‘ action.
    • What to trim: From the dropdown select ‘whitespace characters from the beginning and end‘.

Step 6:

This is where the real magic happens. In this step, we will use The Muhimbi PDF Converter Services Online REST API and convert all documents within a folder to PDF.

Configure it with details mentioned in the section “About the Muhimbi Converter Online API” section and with reference to screenshot below:

Step 7:

Add the “Convert JSON to custom object” action to the Power Automate Canvas and set the parameter below:

  • JSON: %WebServiceResponse% the Output of the “Invoke Web service” action,

Step 8:

The response returned by Muhimbi Service(pdf) is a Base64 string. In this step, we will convert the Base64 string to a file and write the file back to the destination folder using Power Code.

Inside the ‘For each‘ loop add the ‘Run PowerShell script‘ action.

[IO.File]::WriteAllBytes("%CurrentItem.Directory%\%CurrentItem.NameWithoutExtension%.pdf", [Convert]::FromBase64String("%JsonAsCustomObject.processed_file_content%"))

That is it, run the Power Automate Desktop Flow. After a short wait, you will see PDF files in the destination directory.

Subscribe to this blog for the latest updates about SharePoint Online, Nintex, Microsoft Flow, Power Apps, and document conversion and manipulation.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s