Introduction of SAC Multi-Actions Public API - SAP Community
Introduction of SAC Multi-Actions Public API - SAP Community
Community
We have re-enabled the option to post and create content. Email notifications are
currently still turned off while we finish up steps related to badges and content
retagging. Subscribe for more.
manu_xu
Explorer
09-08-2023 5:43 PM
5 Kudos
Background
SAC has delivered multi-actions public APIs in release 2023.15. The APIs can be used to
trigger multi-actions execution and query the execution results afterwards. With this it
offers a flexible way to integrate SAC workflows into external applications to realize
various bussiness scenarios.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 1/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
This blog is supposed to highlight the essential preparations, and to provide some typical
samples to try out the APIs meanwhile you can find more details of the API definitions in
above pages.
Preparation
Multi-actions Public API is supposed to be conducted under business user context. The
API user need to configure the authentication & authorization properly to specify the
desired business user in SAC. Generally there're 2 major options to configure the
authentication and authorization. (Please notice that auth type "client credentials" is
not supported in multi-actions public APIs, since multi-actions cannot be
conducted under technical user context for the time being.)
See
https://help.sap.com/docs/SAP_ANALYTICS_CLOUD/14cac91febef464dbb1efce20e3f16
13/0c1fb5e6ef1f46acb8377..., the part Configuring OAuth 2.0 Authorization Code Grant
Workflow (3-legged OAuth) illustrates how to authenticate and authorize the user
following OAuth2 Authorization Code flow in SAC. (As multi-actions API is supposed to
be conducted under business user context, select "Interactive Usage" as the "Purpose" of
the OAuth client)
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 2/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Besides the authorization code solution, you can leverage the OAuth2 SAML Bearer
Assersion workflow to authenticate and authorize if you have a trusted IdP added to
SAC. One of the restrictions of applying the authorization code workflow is that it
generally requires the end-user to input the credentials to logon SAC explicitly thus to get
the authorization code and continue the authentication. Considering the scenario that the
consumption of multi-actions public API is embedded in a fully automated process with
no user interference possible, you may consider the OAuth2 SAML Bearer Assersion
workflow as an alternative solution as well.
You can use the SAML Bearer Token issued by your IdP to fetch the access token. The
article https://blogs.sap.com/2021/04/09/sap-analytics-cloud-app-integration-with-
oauth2samlbearerassertion-... has introduced the OAuth2SAMLBearerAssertion flows
that can be applied in SAC app integration and has provided some comprehensive
examples on how to apply the flow with and without SAP BTP Destination service
involved.
Before sending HTTP requests with POST method (used in multi-action triggering API),
you need to fetch a valid CSRF token first.
You can get a token by sending a GET request to {tenant-url}/api/v1/csrf, including the
header x-csrf-token: fetch . The csrf token is then returned in the x-csrf-token response
header.
Once you get the token, you can use it to send POST request in the same session (Keep
the JSESSIONID in the cookie as same with the CSRF request). The x-csrf-token:{token}
header must be included in the request.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 3/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
API definitions
Samples
Note
In the following sample we’d use Postman to try out the APIs as it offers friendly user
interface and easy configuration to facilitate the OAuth2 authorization code flow. You can
also try out the APIs with other typical http clients (e.g. curl:
https://curl.se/docs/manual.html, swagger-ui: https://swagger.io/tools/swagger-ui/ and
etc.) , as long as the they have already embedded related authentication/authorization
flow or you can aslo fetch the access token with customzed solution following either
authorization code flow or SAML bearer assersion flow and send the token using the
authorization header.
(To consume the API in swagger-ui, you can download the API specification from
https://api.sap.com/api/MultiActions_API/overview as a reference)
1.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 4/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Create an OAuth Client in SAC, set the purpose as "Interactive Usage", and the
callback url: https://www.getpostman.com/oauth2/callback which is required by
postman.
2.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 5/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
3.
After configuration is done, click on "Get new access token" in the bottom of
"Authorization" tab in postman. After logging on SAC in the pop-up windown, the
access token should be fetched.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 6/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
4.
Then the access token can be used to access the multi-actions public APIs.
Meanwhile csrf token is required to access the API with POST method. Use the
following request to get the csrf token first.
And you will get the csrf token in the headers of response:
5.
Use the csrf token in the following POST request to execute multi-actions. The csrf
token is only valid in the same session, thus make sure the following request use
the same cookie (this is usually taken care by Postman by default and you don't
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 7/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
need to set the cookie explicitly in the following requests in general cases )
6.
Use the query status API to get the status of multi-actions exeuction.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 8/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
The only difference to try out the APIs using the OAuth2 SAML bearer assersion flow
compared to the above authorization code flow lies in the way to get the access token,
and for other part they should be the same. https://blogs.sap.com/2021/04/09/sap-
analytics-cloud-app-integration-with-oauth2samlbearerassertion-... has provided samples
to fetch the access token with and without BTP desitination service. E.g. You can refer to
https://blogs.sap.com/2021/04/08/how-to-generate-saml-bearer-assertion-token-for-
oauth2samlbearerass... to create a nodejs program to get an access token following the
OAuth2 SAML Bearer Assertion flow if you do not have BTP destination at hand. If you
are able to use BTP destination in your solution, it can be even easier and
https://blogs.sap.com/2021/03/24/oauth2samlbearerassertion-flow-with-the-sap-btp-
destination-service... illustrates how to leverage BTP destination to access SAC with
OAuth2 SAML Bearer Assertion flow.
Then start from step 4 in previous authorization code flow sample to use the access
token to access the APIs and the following steps should be the same.
Multi-actions public APIs can be consumed from ABAP/NetWeaver stack thus it can be
feasible to integrate it with products like: BW, BPC and etc. as long as they provide
customized ABAP exits. In following example, we will leverage BTP destination service
(as an identiy provider, it can be replaced with other service serving as role of IdP) to
realize OAuth2 SAML Beaerer Assertion Flow, thus the mutli-actions APIs can be called
from ABAP program with no user interference and it can be embedded in automated jobs
on ABAP/NetWeaver side.
Please also note that the process illustrated below are quite common and you may also
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 9/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
replace the ABAP stack with other programing environment by leveraging corresponding
http clients provided by the selected technology.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 10/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Create an OAuth client in SAC, with "Interactive Usage" as purpose, and there's no need
to define the redirect url.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 11/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Download the IDP metadata, note down the entityID which will be used when adding
trust IdP in SAC.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 12/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Download Trust and copy the public certificate value here, which will also be used in
adding trust IdP in SAC:
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 13/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
create a destination service instance in BTP (if the service did not exist
before)
Open the service key, note down the client id and client secrete which will be used to
access the destination service instance using OAuth2 client credential method.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 14/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 15/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
1 REPORT z_run_multi_actions_in_sac.
2 PARAMETERS:
3 pv_ma_id TYPE string LOWER CASE DEFAULT 'Input multi-actions id here'.
4 DATA lo_client TYPE REF TO if_http_client.
5 DATA lo_rest_client TYPE REF TO if_rest_client.
6 DATA lo_rest_entity TYPE REF TO if_rest_entity.
7 DATA lo_request TYPE REF TO if_rest_entity.
8 DATA lv_body TYPE string.
9 DATA lv_http_status TYPE string.
10 DATA lv_response TYPE string.
11 DATA lv_acc_token_to_destination TYPE string.
12 DATA lv_acc_token_to_sac TYPE string.
13 DATA lv_csrf TYPE string.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 16/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 17/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Query the destination via destination service to fetch the access token to
access SAC
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 18/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 19/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 20/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 21/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
1 *----------------------------------------trigger multiactions--------------
2 DATA lv_url TYPE string.
3 lv_url = '<your SAC url>/api/v1/multiActions/' && pv_ma_id && '/executions'
4 cl_http_client=>create_by_url( EXPORTING url = lv_url IMPORTING client = lo
5
6 CALL METHOD lo_client->request->set_method( if_http_request=>co_request_met
7 lo_client->request->set_header_field( name = 'x-csrf-token' value = lv_csrf
8 lo_client->request->set_header_field( name = 'Authorization' value = lv_acc
9 lo_client->request->set_header_field( name = 'Content-Type' value = 'applic
10 lo_client->request->set_cookie( name = 'JSESSIONID'
11 value = lv_decoded_cookie ).
12 lv_body = '{"parameterValues": [ ]}'.
13 lo_client->request->set_cdata( data = lv_body ).
14 CALL METHOD lo_client->send
15 EXCEPTIONS
16 http_communication_failure = 1
17 http_invalid_state = 2
18 http_processing_failed = 3.
19
20 ASSERT sy-subrc = 0.
21
22 CALL METHOD lo_client->receive
23 EXCEPTIONS
24 http_communication_failure = 1
25 http_invalid_state = 2
26 http_processing_failed = 3.
27 lv_response = lo_client->response->get_cdata( ).
28 WRITE: lv_response.
29 WRITE: / 'Trigger multi-actions ' && pv_ma_id && ' successfully'.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 22/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
SAP Build Process Automation (will use "BTP PA" to indicate the platform in the following
descriptions) is a low-code platform available on BTP which can be used to build
workflow across SAP/non-SAP applications. (https://www.sap.com/products/technology-
platform/process-automation/features.html) We can also embed multi-actions API in the
process of BTP PA to achieve corresponding business needs. Here are some key steps of
configuration:
security configuration
Create an OAuth Client in SAC like what's mentioned in above ABAP/Netweaver section.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 23/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
In URL, add the suffix "api/v1" to sac tenant url, such as: https://{tenant url}/api/v1
sap.applicationdevelopment.actions.enabled = true
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 24/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
sap.processautomation.enabled = true
SystemUser is not necessary as you can config use the user who start the
BTP PA process as the user to trigger multi-actions
Add the BTP destination as trusted IdP in SAC, similar procedure has also been
introduced in the above "ABAP/Netweaver" section.
Configuration in BTP PA
Open BTP PA, go to the "settings" tab and add your destination configured in above
steps.
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 25/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Go to the "lobby" tab, click "create" button and select to "build an automated process",
and then select "actions".
Click "upload API specification" and upload the multiActions API specification
Enable csrf setting for the action both in the action setting and the post request:
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 26/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 27/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Create a process, add the trigger-multi-actions request as a step of the process from the
action library:
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 28/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Click on the multi-actions step we just added, create a destination variable which will be
used to bind the destination when we deploy the process:
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 29/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Configure to run action on behalf of the user starts the process (the user should exist in
SAC as well
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 30/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Go to the monitor tab of BTP PA, click on "Manage - Porcesses and Workflows", select
the process we just deployed, click on "Start new instance"
Provide the input of the process in Json format, and click on "start new instance":
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 31/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
1 {
2 "pmaid": "t.7:FD000504F025851615C5037A42DD56BE",
3 "pparameter":
4 {
5 "parameterId": "TargetVersion",
6 "value": {
7 "memberIds": [
8 "public.Actual"
9 ],
10 "hierarchyId": ""
11 }
12 }
13 }
In "monitor - Process and Workflows", you can view the status of process:
(end)
Labels:
Technology Updates
Tags:
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 32/33
1/28/24, 11:43 AM Introduction of SAC Multi-actions Public API - SAP Community
Comment
Event Information2 Expert Insights 177 Expert Insights 4 Life at SAP 786
Technology Updates 10
Related Content
How to add a new field to the RAP BO of a customizing table
in Technology Blogs by SAP 2 weeks ago
Empowering ALM Excellence: Navigating the SAP Cloud ALM Journey with CAS Core
Operations service for Cloud ALM
in Technology Blogs by SAP 3 weeks ago
P l Bl P t
https://community.sap.com/t5/technology-blogs-by-sap/introduction-of-sac-multi-actions-public-api/ba-p/13577173 33/33