Using data passed via Robocorp Cloud Process API in your robot code

When you enable the Process API for one of your processes in Robocorp Cloud, you can then trigger it via an API call.

The API also allows you to pass additional data in JSON format to the process.

To be able to access the data you send in your robot code, you will use the RPA.Robocloud.Items library, part of the rpaframework.

Here is a very simple example of an robot using the library:

*** Settings ***
Documentation     Simple Robot to demonstrate how to use variables from the Work Item,
...               passed via the Robocorp Cloud Process Api
Library           RPA.Robocloud.Items

*** Tasks ***
Log A Message Passed Via The Robocorp Cloud Process API
    ${MESSAGE}=    Get Work Item Variable    message
    Log    ${MESSAGE}

Notice that:

  • we added the RPA.Robocloud.Items library in the *** Settings *** section.
  • we are accessing a single variable with the Get Work Item Variable keyword.

If we trigger this robot in Robocorp Cloud via the Robocorp Cloud Process API, passing this JSON as the request body:

{
  "variables": {
    "message": "Hello World!"
  }
}

Note that the message property is nested in the variables property.

We will get this resulting log:

Log of executed robot

You can use this technique to pass any information you need dynamically to your robots and processes in Robocorp Cloud.

An alternative approach

You can also make your robots more dynamic using environment variables.