How to integrate MuleSoft RPA and Anypoint APIs

Reading Time: 5 minutes

MuleSoft RPA automation 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 cannot 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 and other Salesforce Hyperautomation systems. In this article, I will demonstrate how to integrate 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 automation 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 with a Process API (PAPI) that needs to get data from two different System APIs (SAPIs) and consolidate both results. Each SAPI interacts with different e-commerce 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 e-commerce platforms is a legacy system with no API available, and there is no way to access the data other than manually signing in to the web site and searching for it.

A legacy system with no API.

This is where MuleSoft RPA comes into play. Instead of having a real person manually sign in and search 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 into 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.

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 Automation 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 immediately 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 optimise 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 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 to send 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 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 and reliable, giving you more control over the callback.

Let’s get started.
Reach out to us
for a conversation!

Fill in the form below and we will get back to you

Don’t Miss Out!

Stay in the loop on the latest in the wild world of technology and AI. Subscribe for updates on our newest articles and exclusive events, it just Makes Sense!