Use Case: Making a Multipart API Call in Unqork

Overview

Making a multipart API (application programming interface) call in Unqork still requires a Plug-In component. But you'll also use a Calculator component to define the MIME Types (Multipurpose Internet Mail Extensions) included in your request. Let's look at a common example of sending a Base 64 encoded PDF in a POST call.

NOTE  You won’t need to use multipart API calls for Unqork services. This example shows the steps you’d follow once you’ve set up an integration that requires a multipart API call. That means you won't be able to actually perform this call in Preview. This is only an example.

What You’ll Need

To set up this use case, you’ll need:

  • 3 Hidden components.

  • 1 Plug-In component.

  • 1 Calculator component.

  • 1 Button component.

Configuration

Configure the Hidden Components

The first two Hidden components will hold the PDF MIME Type and the Base 64 encoding for the PDF. Later, you’ll set up a Calculator component to bring them together.

1. Drag and drop the first Hidden component onto your canvas.
2. Enter base64OfFile in the Property ID and Label Text fields.
3. Click Save.
4. Drag and drop a second Hidden component onto your canvas. Place this component below the first Hidden component.
5. Enter mimeType in the Property ID and Label Text.
6. Enter application/pdf in the Default Value field.

NOTE  In this case, our MIME type is a PDF. You’ll replace application/pdf with whatever MIME type you’re using.

7. Click Save.

Configure the Calculator Component

Your Calculator takes the values in your first 2 Hidden components and combines them. The Calculator will put the combined value in the encodedFileURI we’ll add in the next step.

1. Drag and drop a Calculator component onto your canvas.
2. Enter calcMimeType in the Property ID and Label Text.
3. In the Inputs table, enter the following:

Property ID

Alias

Required

base64OfFile

pdf

Yes (checked)

mimeType

mime

Yes (checked)

4. In the Outputs table, enter the following:
a. Property ID: enter encodedFileURI.
b. Formula: enter =CONCATENATE('data:',mime,';base64,',pdf).

5. Click Save.

Configure the Hidden Component

This is the third Hidden component in this configuration. This serves as the output for the Calculator component.

1. Drag and drop a Hidden component onto your canvas. Place your Hidden component below your Calculator.
2. Enter encodedFileURI in the Property ID and Label Text.
3. Click Save.

Configure the Plug-In Component

This Plug-In component handles the API call. Here, you'll specify that you're making a multipart API call. Again, these instructions assume that you've already set up an API in Services Administration. In the following steps, you'll select that API from the Services drop-down.

1. Drag and drop a Plug-In component onto your canvas.
2. Enter pluginMultipartApiCall in the Property ID and Label Text.
3. Select Manual from the Trigger Type.
4. In the Inputs table, enter the following:
a. Property ID: enter encodedFileURI.
b. Mapping: enter file.
c. Required: Yes (selected).

5. Select your API call from the Internal Services drop-down. The Data Source URL automatically populates.
6. Select POST as the Request Type.
7. Set the Make a Multipart API Call toggle toON.

NOTE  A box appears letting you enter an Alternative Multipart Sub-Type. If your API requires a type other than multipart/form-data, enter it here.

8. Click Save.

Configure the Button Component

The Button component will trigger your Plug-In when clicked, ultimately executing the API call.

1. Drag and drop a Button component onto your canvas.
2. Enter btnsubmitMultipartCall in the Property ID.
3. Enter Submit Multipart Call in the Label Text.
4. Select Event from the Button Action Type.
5. Enter pluginMultipartApiCall in the Trigger on Click field.

6. Click Save.
7. Save your module.

Lab

You can view the completed lab for this multipart API use case here: https://training.unqork.io/#/form/5edff545588ae0020f50fe81/edit.