In this blog I will show, how you can use the SAP Intelligent RPA 2.0
Low-Code/No-Code approach on top of the SAP Analytics Cloud REST API.
Knowing the concepts can be very useful also when you are working with
other SAP Applications, Here a similar blog for
SAP BusinessObjects.
You will learn how to
- create Automations for reuse in other projects (like Activities provided by the Intelligent RPA SDK packages)
- generate and share a reusable Package
- use a Data Type and Input and Output Parameters
- use Javascript in the Custom script Activity (REST requests using the irpa_core.request() method)
- the basics of using the REST API and get a template you can use to implement your own requirements
Overview
In the first part, I will create a Project and Package with some sample automations for the SAP Analytics Cloud Tenant (Logon, Logoff, Team). Here we will use the SAP Analytics Cloud User and Team Provisioning API, so this part needs Javascript skills and is typically done by
Expert Bot Developers.
In the second part, we will create another Project and here we can use the package created in the first part. This will allow
Citizen Developers or
Business Process Experts to define automations, no coding skills are needed.
The final automation in Cloud Studio:
For general information regarding SAP Intelligent RPA (videos, blogs, openSAP courses) please read the blog
SAP Intelligent RPA – enablement and getting started there is also a free
trial.
For the configuration of your SAC tenant, please find the information in the blog
SAC: Export user list by REST API (sections:
Setup in SAC and
Required URLs)
Updates
Version 2103
- Automation Team - CustomScript can be used to add Teams
make sure to update to the latest SAP Intelligent RPA Core SDK package
- Parameter name generatedObject is now called myVariable
the steps below and screens still use generatedObject, you will use myVariable instead
- Sometimes you have to save the automation first before you can select the mentioned parameter
First Part: Project and Package
We will create a New
Project, a
Data Type to manage session parameters and
Automations for Logon, Logoff and to manage the SAP Analytics Cloud Team. Finally we generate a
Package from the project and this package will be used in the second part.
- Create a New Project
- Use the Project name: SAC REST-API CustomScript Sample
- To work with the REST API of Analytics Cloud, the SAP Intelligent RPA Core SDK is required.So make sure this package is added to your project.
If the Core SDK package is not available on your tenant, you can acquire it from the Store.
- Select Dependencies - Manage Dependencies
- Add Dependency
- You will find the package in the list
- Select Create - Data Type
- Use the name dtSessionSAC
- Define the fields of the data type as show in the picture below
- use New Field to add a new row
- use New Child to group parameters, here name and secret of the oAuthClient
- Select Save
Automation - Logon
Automation - Logoff
Automation - Team
Most of the steps are the same like for the Automation - Logoff, so we will just have screens for the differences. To keep it simple in the sample it is only possible to add a team, but the automation could be enhanced to delete a team, ...
- Select Create - Automation
- Use the name Team - CustomScript for the automation
optional description: Manage Teams in SAP Analytics Cloud using the REST API
- Select I/O to define an Input parameter
The automation will use the session created with the Logon - Custom Script automation.
name: sessionSAC
select type dtSessionSAC from the list
in addition we have the parameters
- method: to define if a team should be added, deleted, ...
- name: the name of the team
- Add the activity Custom Script to your automation
- Select the activity Custom script in the flow diagram and select Edit Script
- Select Add new input parameter
- Enter Input parameter name pSession and select type dtSessionSAC from the list
- Select Add new input parameter
- Enter Input parameter name method and select type String from the list
- Select Add new input parameter
- Enter Input parameter name name and select type String from the list
- Copy the following script code to line 1
// use get groups with a not existing group to get the x-csrf-token
async function fetchToken() {
const options = {
resolveBodyOnly : true,
responseType: 'json',
url: pSession.tenantScimURL + 'Groups/xy',
method: 'GET',
headers: {
'Accept' : 'application/json',
'Content-Type': 'application/json',
'Authorization' : 'Bearer ' + pSession.accessToken,
'x-sap-sac-custom-auth' : 'True',
'x-csrf-token': 'fetch'
}
};
try {
const response = await irpa_core.request.call(options);
} catch (error) {
pSession.csrfToken = error.response.headers['x-csrf-token'];
}
}
const options = {
resolveBodyOnly : true,
responseType: 'json',
headers: {
'Accept' : 'application/json',
'Content-Type': 'application/json',
'Authorization' : 'Bearer ' + pSession.accessToken,
'x-sap-sac-custom-auth' : 'True',
}
};
if (method === 'get') {
options.url = pSession.tenantScimURL + 'Groups/' + name;
options.method = 'GET';
const response = await irpa_core.request.call(options);
irpa_core.core.log(response.id + ', members: ' + response.members.length);
} else if (method === 'add') {
// needs an additional feature in the CORE SDK - irpa_core.request()
// currently the use of 'tough-cookie' is not possible in a custom script
// this request will fail with error: Response code 403 (Forbidden)
if (pSession.csrfToken.length === 0) {
await fetchToken();
}
options.url = pSession.tenantScimURL + 'Groups';
options.method = 'POST';
options.headers['x-csrf-token'] = pSession.csrfToken;
options.body = JSON.stringify({
'id': name,
'displayName': name,
'members': [],
'roles': []
});
//irpa_core.core.log(options);
const response = await irpa_core.request.call(options);
}
- You should have the following definition
red marker is an indicator, that the input parameter is missing (see next step)
- Select Custom Script in the flow diagram
- For parameter pSession, select sessionSAC from the list
this is the Input Parameter for our automation, created with the Logon automation
- For parameter method, select method from the list - input parameter of our automation
For parameter name, select name from the list - input parameter of our automation
- Save the automation
Test the automations
Now you can test the Logon, Team and Logoff in a new automation, which you probably would do to make sure everything works fine. You can also use easily debugging features of Cloud Studio when testing in the same project.
As we are now
creating a package from our project, we will use the package in the second part and also test our automations in the second project.
Generate and Share the Package
- Select Projects
- On the sample project select the icon Generate Package
- Confirm the name and select Generate Package
- Select Packages
- On the package select More Options and Share
- On Share Package set Share with: Anyone and Authorization: Read, click on Share
- Your Package is now shared and can be used in Projects
Second Part: No-code Project
Now we will create and test an automation using the package.
Remember: starting with version 2103 you can not only read a team, you can also create a team. Just specify method
add.
Automation - Read Team
- Create a New Project
- Use the Project name: Demo SAC
- Select Dependencies - Manage Dependencies
- Select Other and click Add Dependency
- Select the Package and Version from the list and click Add
- The package is in the list, select close
- Select Create - Automation
- The Configure agent version may be displayed - select your installed agent version and confirm
- Use the name Read Team for the automation
- Add the automations Logon, Team and Logoff to your flow
- Select each step and rename the steps, use
Logon – SAP Analytics Cloud
Read Team Members
Logoff – SAP Analytics Cloud
- Select step Read Team Members and set the Input Parameters
sessionSAC from the list
get string as method
Admin string for the Team name to read (should be a team that exists in your SAP Analytics Cloud tenant)
- Select step Logoff - SAP Analytics Cloud and set the Input Parameter
sessionSAC from the list
- Save the automation
Test the automation
- Select Test
- Select your Environment
- The automations should be executed and the no, of members from Team Admin will be displayed in the console
Click on Info if the information is not visible
Conclusion
You have used several
key concepts, how to
- create Automations for reuse in other projects (like Activities provided by the Intelligent RPA SDK packages)
- generate and share a reusable Package
- use a Data Type and Input and Output Parameters
- use Javascript in the Custom script Activity (REST requests using the irpa_core.request() method)
- the basics of using the REST API and a template you can use to implement your own requirements
Hope this was useful and you can now start your own journey in using the REST API of your SAP Application.