How to Integrate MuleSoft RPA and Anypoint APIs

Jose Luis Clua
Another Integration Blog
6 min readFeb 21, 2024

MuleSoft RPA automations and Anypoint Platform APIs can be integrated to achieve the best of both worlds: Process Automation and System Integration. RPA was brought into the Salesforce ecosystem because there are certain scenarios where Anypoint APIs are not able to reach the data we need, for example, extracting information from images or interacting with legacy systems. But that doesn’t mean MuleSoft RPA needs to do all the work by itself, it can be integrated with Anypoint APIs as well as other Salesforce Hyperautomation systems. In this article we will demonstrate how to integrate a Mulesoft RPA automation with an Anypoint API.

What you will need

First things first, let’s go through some prerequisites and environments needed if you plan to develop MuleSoft RPA automations integrated with Anypoint APIs.

Sample Use Case

We could think of many scenarios where Bots and REST APIs could work together. To illustrate this article, I’ve created a sample use case where we have a Process API (PAPI) that needs to get data from two different System APIs (SAPIs) and consolidate both results. Each SAPI interacts with different ecommerce platforms. Both platforms use the same IDs for their products and generate lists of stores and prices given a product ID. The PAPI needs to identify which are the stores with the best prices for all products.

The Challenge

Let’s imagine that one of these ecommerce platforms is a legacy system with no API available and there is no way to access the data other than manually signing in the web site and searching for it.

Legacy system with no API

This is where MuleSoft RPA comes into play. Instead of having a real person manually signing in and searching for products, with RPA, we could have a Bot performing this task.

Using MuleSoft RPA Bot to unlock Legacy data

To achieve this integration, we need to answer these questions:

  • How will the SAPI interact with the Bot?
  • How will the Bot send its findings back to the SAPI?

Invoking Automations from APIs

A MuleSoft RPA automation can easily be exposed as a REST API just by being published in Anypoint Exchange, this will create what we call an Automation API. This is done in RPA Manager once you reach the production phase of your RPA development lifecycle. In the production configuration you will see an option to create an invokable run configuration.

Create an Invokable run configuration

If you have your Connected App properly set up in Anypoint Platform Access Management, this will generate the Automation API and expose the automation to other APIs and systems within the Salesforce Hyperautomation suite such as Flow Builder and MuleSoft Composer.

RPA reusability

The Automation APIs will be automatically generated with the following endpoints created out-of-the-box:

  • PUT executions/startProcess. Starts the automation process in an idempotent manner. Input parameters can be sent in the request body.
  • POST executions/startProcessNonIdempotent. Starts the automation process in a non-idempotent manner. It will immediately return an executionId. Input parameters can be sent in the request body.
  • GET executions/{executionId}/getProcessExecutionStatus. Get the status of the execution given the executionId. When the execution status is “success” it will return a map containing the values of all output parameters, in other words, all data processed and collected by the Bot. Other possible statuses are: “notStarted”, “running” and “error”.
Automation API endpoints

The Automation API can be imported in Anypoint Studio projects as a custom connector or invoked directly using the HTTP request connector. These connectors can trigger the RPA Bot to start the automation in the environment in which the Bot was deployed to.

RPA Automation API Connector

The request body in the startProcess and the startProcessNonIdempotent endpoints will take the following object:

{
"callbackUri": "https://rpa-demo-sapi-xxx.usa-e2.cloudhub.io/api/callback",
"label": "callback",
"inputArguments": {
"prodCode": "1001"
...
}
}

We will talk more about the callbackUri attribute a bit later. The inputArguments hold the Activity Parameters in the automation. Activity Parameters in MuleSoft RPA can work for both input and output parameters. So, in our example, we could send the product code we want to search as an input parameter, from the SAPI to the automation.

Sending data back from Automations to APIs

So far, we’ve seen how the SAPI can start the automation and send parameters to it. When the Bot finishes its job, how can the SAPI access the data processed by the Bot? There are different options for this:

  • Using the getProcessExecutionStatus endpoint
  • Using the built-in callbackUri attribute
  • Creating a custom callback function

When using the startProcessNonIdempotent endpoint we imediately receive an executionId , with which we can get the process status at any time using the getProcessExecutionStatus endpoint. We could use the until successful scope and try, every few seconds, until we get the “success” result and get all the data from the Bot. That way we would be making the process synchronous. The SAPI keeps trying until the results from the Bot are available and, once they are, it continues its flow.

The callbackUri is a resource indicator to which, if provided, the automation will send a PUT request after the Bot completes its execution, sending all of the Activity Parameters in its payload.

To optimize the process, we could make it asynchronous by using the callbackUri and creating a callback endpoint in our SAPI so that its HTTP listener routes the PUT request from the Bot to a flow where we can handle the event, for example, publishing the results to a queue or a topic which will add reliability and event-driven attributes to our design.

Asynchronous design to send data from Bot to SAPI

If we want to have more control, we could also create a custom callback function. In the last step of the automation, using MuleSoft RPA Builder, we could add a REST Call function and, programmatically, execute the callback to the System API as soon as the Bot completes its work.

Custom callback function

The REST Call function can be added within a Managed block which can be used for error handling, similar to a Try/Catch block. The call can be configured so that it sends only the relevant data processed by the Bot back to the API and not all Activity Parameters. This function will also give you access to other parameters such as method type, headers, authentication, etc.

REST Call Wizard

Conclusion

For an Anypoint API to interact with a MuleSoft RPA automation we just need to publish it in Anypoint Exchange, which will generate an Automation API enabling external systems to communicate with it.

There are different options for sending automation results back to an API. Creating an asynchronous design with a custom callback function and publishing the results processed by the automation into a message broker is a great approach because it will be event-driven, reliable and it will give you more control over the callback.

--

--