Create and use an external API

Introduction

This guide outlines the process of integrating an API into an application to facilitate communication with a second application. In this example, when a new user is created in our application, a workflow triggers an external API call to an external application to verify if the user already exists. If the user is found, their information is updated accordingly.

N.B: You need to have the API’s documentation in hand.

Step-by-step instructions

Step 1 to 3 are to configure the API connexion. Skip to Step 4 to see how to use the external API

1. Add Connection (Account)

From Account, open the External API section of our application page and add a connection to an external application by completing the API’s configuration.

2. Create External API

Once signed in to our application, add an external API (Projet Explorer panel, More ­­­­­­­> APIs > External). Select the Connection made in step 1, give a name to the External API, a Route, and choose a Method. The Route and Method must be provided from the API (external application). Request Body will usually be JSON.

Then, add parameters to the new External API. In this example, the email parameter was added.

3. API Test

To see if the API call works, make the External API ¨Callable from application UI¨ from the properties of the API and add a test.

Testing is done by manually adding values, one valid and one invalid. To add those values, select the parameter to test from the external API and open its properties.

Execute the test from the API properties section. The result will be displayed below. These results will help dictate the names of the fields that will be created in step 4.

The data type of the reply will vary according to the external API used.

Here is a success example:

{
code: 202, 
status: success,
user_email: "firstLastName@gmail.com",
dateOfBirth: 01/01/1981
}

And here is an error example, informing you that an email field is missing.

{
	"code": 400,
	"error" : "Bad request",
	"message": "Missing email field"
}

4. Manage API Responses

To enable the use of the API response in the Workflow step (step 5), it must first be modeled. Create an ¨API Response¨ aggregate. This will allow our application to read the data from the reply of the API call. Create the appropriate fields according to the expected data. Be sure to add an Error and Message field as well.

It is essential that the field names exactly match those returned in the API response.

5. Workflow

To process data from an API response, use an Event Trigger workflow (this one triggers when a new user is created) along with the Invoke External API activity unit (to select the api to call with its parameter and store the response in the APIResponse schema just created). Incorporate an If unit to halt the workflow if an error is detected in the response. The Execute Command unit then triggers the update command and retrieves two specific fields—birthdate and phone—based on the API response from the external application.

Conclusion

Implementing these steps allows an application to integrate an external API effectively to enable seamless communication between systems. This integration ensures data consistency, reduces redundancy, and enhances operational efficiency. Proper API configuration, thorough testing, and automated workflows contribute to maintaining data accuracy and optimizing system interactions.