Integrate pdfRest with Microsoft Power Automate
Overview
Microsoft Power Automate is a convenient tool for streamlining the creation of automated workflows. Its web interface supports the connection of hundreds of services with minimal coding requirements. While pdfRest is not currently listed within the Power Automate marketplace, pdfRest is callable as a REST API service, allowing for easy integration with Power Automate workflows and other low/no-code services.
Take a minute to sign up for a free Starter account with pdfRest to generate a dedicated API Key, which will be required for sending calls to the service.
Watch the video for a quick guided tour then follow along with complete step-by-step instructions below:
Tutorial
When working with pdfRest in Power Automate, there will always be one or more initial steps that precede the document processing steps. In other words, something has to happen first that triggers pdfRest to kick into action. These preceding hooks/steps/flows can be customized to meet your specific workflow needs. All that really matters is that at some point, you end up with one or more files that are ready to be processed using any of the API Tools within the pdfRest toolkit. The following tutorial will demonstrate a flow that is triggered when an image file is uploaded to a OneDrive folder. This image file will automatically be processed with the pdfRest Convert to PDF tool, and the resulting PDF will be downloaded back into another folder in OneDrive.
Once you've set up your initial steps that produce one or more files, the first action required for integration with pdfRest is HTTP
, which is a Power Automate premium offering and will require a license:
With a premium license setup, type ‘http’ in the search box, and select the basic HTTP
action as shown below:
Now you're ready to send your first call to pdfRest, which will use the Upload Files tool to prepare files for subsequent processing steps.
- For
Method
, selectPOST
- For
URI
, enter the endpointhttps://api.pdfrest.com/upload
- Under
Headers
, you will need to addApi-Key
followed by your dedicated API Key (shown here as XXXXXXXXXXX) - Under
Body
, you will need to construct the request. This can be done by copying the template below and changing just two parts:- Insert the content of the file you are uploading into the
“body”:
section (shown here pulling from the preceding OneDrive step) - Insert the name of the file you are uploading into the
filename=
section of theContent-Disposition
. NOTE: This can be done dynamically if you are uploading a wide variety of files and/or want their precise name(s) preserved after upload or by just entering in a static, generic name liketestfile.png
if you know you are only going to be processing one type of file or plan to name the output file with a different name.
- Insert the content of the file you are uploading into the
Body:
{ "$content-type": "multipart/form-data", "$multipart": [ { "body": CONTENTS_OF_FILE, "headers": { "Content-Disposition": "form-data; name=file; filename=NAME_OF_FILE" } } ] }
At this point, you can test the flow, and if this step succeeds, you will see a success with a return that looks similar to the following response:
{ "files": [ { "name": "testfile.png", "id": "2bcfb3082-2701-4de2-af69-b6e128559eee" } ] }
Now that you have a step that is uploading a file and returning a JSON response, you'll need to parse the JSON to retrieve the resource ID so that you can pass this on to the next processing step. Search for "json" to find the Parse JSON
action.
Within this step you will need to pipe the Body
of the previous Upload File
step into the Content
field:
You can then copy the output JSON from the previous step’s test run, press the Generate from sample
button, paste the copied sample output, and it will automatically detect the schema for you:
If everything is successful, your Parse JSON
step will look something like this:
Next, you will create another HTTP
step, just the same as you did before, with the only differences being the URI (this will be the endpoint of the API Tool you select for processing, https://api.pdfrest.com/pdf
for this example), and the Body
, which will be JSON containing the ID from the previous step and any other required or optional parameters for the selected endpoint. Please consult the API Reference Guide for complete documentation details.
For this example, you will be sending a call to the /pdf
endpoint with only the id
that you parsed out of the Upload step:
Note that when you put the dynamic id
into the file processing step it will immediately and automatically create an Apply to each
wrapper around the step. This is because the upload functionality of the API actually allows both single and multiple file uploads in a single action and thus returns an array of uploaded files. In this example, you are only uploading and using one file, but Power Automate still noticed that there could be multiple. This does not change anything, aside from the fact that the rest of your process will be built within this Apply to each
wrapper.
When this Convert to PDF
call (or any other pdfRest call) succeeds, it will return a JSON output in the form:
{ "outputUrl": "https://api.pdfrest.com/resource/XXXXXXXXXXX?format=file", "outputId": "XXXXXXXXXXX", "inputId": "YYYYYYYYYY" }
Once again, you will need to parse the JSON response using the Parse JSON
action by piping the Body
into the Content
field and copy/pasting a test response into the Schema
.
At this point, you can continue chaining calls by adding more pairs of HTTP
and Parse JSON
steps, passing the ID from a previous step into a new processing step.
To complete this example, you can pipe the outputUrl
from the previous Parse JSON step directly into an Upload file from URL
action to upload the output PDF file back into OneDrive for storage.
Of course, you can customize the end step to pass pdfRest output files anywhere you need to send them for the next steps in their journey.
Support
If you have any trouble getting this set up or would like more information about how pdfRest can solve your PDF processing challenges, please let us know how we can help!