EDUCAÇÃO E TECNOLOGIA

Use SAP Analytics Cloud REST API with SAP Intelligent RPA – Automations

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,

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

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 Citizien 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)

Limitation of the Core SDK when using the SAP Analytics Cloud REST API

With the current version of the SAP Intelligent RPA Core SDK – HTTP Request module, we cannot use API methods that will create or update Teams, Users, … in SAP Analytics Cloud.
For this methods the x-csrf-token is needed and this requires an dedicated cookie handling which is currently not implemented in the Core SDK.
This is planned to be available in a newer version of the SAP Intelligent RPA Core SDK.
The sample code in the Team automation of this tutorial is already prepared, so you can see how it must be implemented in your Javascript code.I will update the blog when the functionality is available.

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.

Automation – Logon

Automation – Logoff

  • Select Create – Automation
  • Use the name Logoff – CustomScript for the automation
    optional description: Logoff from SAP Analytics Cloud using 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
  • 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
  • Copy the following script code to line 1
    // currently no request, clear only the session object
    pSession.accessToken = '';
    pSession.csrfToken = '';​
  • 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
  • Save the automation

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 + '/v1/usergroups/usergroup'; 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 Packaged is now shared and can be used in Projects

Now we will create and test an automation using the package.

Automation – Read Team

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

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.