Introduction of SAC Multi-Actions Public API - SAP Blogs
Introduction of SAC Multi-Actions Public API - SAP Blogs
Community
Follow
Technical Articles
Manu Xu
September 8, 2023 | 14 minute read
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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 1/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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
Authentication & Authorization
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.)
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-flow./ 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.
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 2/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
Before sending HTTP requests with POST method (used in multi-action triggering
API), you need to fetch a valid CSRF token first.
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.
API definitions
Please refer to SAC help:
https://help.sap.com/docs/SAP_ANALYTICS_CLOUD/14cac91febef464dbb1efce20
e3f1613/e5ade1ed7c274d929a18bcc859102c40.html for details of the API
definitions and we won’t repeat it in this article.
Samples
Try out the APIs using some common http clients
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)
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 3/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 4/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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:
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 5/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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 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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 6/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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.
Please also note that the process illustrated below are quite common and you may
also replace the ABAP stack with other programing environment by leveraging
corresponding http clients provided by the selected technology.
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 7/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 8/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 9/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
Download the IDP metadata, note down the entityID which will be used when adding
trust IdP in SAC.
Download Trust and copy the public certificate value here, which will also be used in
adding trust IdP in SAC:
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 10/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
create a destination service instance in BTP (if the service did not exist before)
Create a destination service instance in BTP if there’s no available service instance
created before.
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 11/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 12/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
REPORT z_run_multi_actions_in_sac.
PARAMETERS:
pv_ma_id TYPE string LOWER CASE DEFAULT 'Input multi-actions id here'
DATA lo_client TYPE REF TO if_http_client.
DATA lo_rest_client TYPE REF TO if_rest_client.
DATA lo_rest_entity TYPE REF TO if_rest_entity.
DATA lo_request TYPE REF TO if_rest_entity.
DATA lv_body TYPE string.
DATA lv_http_status TYPE string.
DATA lv_response TYPE string.
DATA lv_acc_token_to_destination TYPE string.
DATA lv_acc_token_to_sac TYPE string.
DATA lv_csrf TYPE string.
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 13/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
lo_request = lo_rest_client->create_request_entity( ).
lo_request->set_content_type( iv_media_type = 'application/x-www-form-
lv_body = 'grant_type=client_credentials&client_id=<your oauth client
lo_request->set_string_data( lv_body ).
lo_rest_client->post( EXPORTING io_entity = lo_request ).
lv_http_status = lo_rest_client->get_status( ).
lo_rest_entity = lo_rest_client->get_response_entity( ).
lv_response = lo_rest_entity->get_string_data( ).
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 14/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
json = lv_response
pretty_name = /ui2/cl_json=>pretty_mode-user
assoc_arrays = abap_true
CHANGING
data = lr_data ).
IF lr_data IS BOUND.
ASSIGN lr_data->* TO FIELD-SYMBOL(<lfs_data>).
ASSIGN COMPONENT 'access_token' OF STRUCTURE <lfs_data> TO FIELD-SYM
ASSIGN <lfs_results>->* TO FIELD-SYMBOL(<ld_token_value>).
WRITE: 'Get access to destination service successfully'.
ENDIF.
lv_acc_token_to_destination = <ld_token_value>.
Query the destination via destination service to fetch the access token to access SAC
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 15/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
lo_request = lo_rest_client->create_request_entity( ).
lo_request->set_content_type( iv_media_type = 'application/x-www-form-
lv_body = 'grant_type=client_credentials&client_id=<your oauth client
lo_request->set_string_data( lv_body ).
lo_rest_client->post( EXPORTING io_entity = lo_request ).
lv_http_status = lo_rest_client->get_status( ).
lo_rest_entity = lo_rest_client->get_response_entity( ).
lv_response = lo_rest_entity->get_string_data( ).
IF lr_data IS BOUND.
ASSIGN lr_data->* TO FIELD-SYMBOL(<lfs_data>).
ASSIGN COMPONENT 'access_token' OF STRUCTURE <lfs_data> TO FIELD-SYM
ASSIGN <lfs_results>->* TO FIELD-SYMBOL(<ld_token_value>).
WRITE: 'Get access to destination service successfully'.
ENDIF.
lv_acc_token_to_destination = <ld_token_value>.
lo_rest_client->set_request_header(
EXPORTING
iv_name = 'X-CSRF-TOKEN'
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 16/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
iv_value = 'FETCH' ).
lo_rest_client->set_request_header(
EXPORTING
iv_name = 'Authorization'
iv_value = lv_acc_token_to_sac ).
lo_rest_client->get( ).
lv_http_status = lo_rest_client->get_status( ).
lo_rest_entity = lo_rest_client->get_response_entity( ).
lv_csrf = lo_rest_entity->get_header_field( 'X-CSRF-TOKEN' ).
DATA lt_headers TYPE tihttpnvp.
DATA ls_header TYPE ihttpnvp.
lt_headers = lo_rest_entity->get_header_fields( ).
DATA lt_cookies TYPE TABLE OF string.
DATA lv_cookie TYPE string.
DATA lv_cookie_remaining TYPE string.
LOOP AT lt_headers INTO ls_header.
IF ls_header-name = 'set-cookie'.
IF ls_header-value CS 'JSESSIONID='.
SPLIT ls_header-value AT ';' INTO lv_cookie lv_cookie_remaining
lv_cookie = lv_cookie+11.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
*WRITE: lv_csrf.
DATA lv_decoded_cookie TYPE string.
lv_decoded_cookie = cl_http_utility=>unescape_url(
escaped = lv_cookie ).
WRITE: / 'Get csrf token from SAC public api service'.
*WRITE: lv_csrf.
*WRITE: lv_decoded_cookie.
*----------------------------------------trigger multiactions---------
DATA lv_url TYPE string.
lv_url = '<your SAC url>/api/v1/multiActions/' && pv_ma_id && '/execut
cl_http_client=>create_by_url( EXPORTING url = lv_url IMPORTING client
ASSERT sy-subrc = 0.
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 18/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
security configuration
Create an OAuth Client in SAC like what’s mentioned in above ABAP/Netweaver
section.
In URL, add the suffix “api/v1” to sac tenant url, such as: https://{tenant
url}/api/v1
In additional properties, add
sap.applicationdevelopment.actions.enabled = true
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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 19/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 20/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 21/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
Create a process, add the trigger-multi-actions request as a step of the process from
the action library:
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://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 22/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
Configure to run action on behalf of the user starts the process (the user should exist
in SAC as well ):
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 23/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
Provide the input of the process in Json format, and click on “start new instance”:
{
"pmaid": "t.7:FD000504F025851615C5037A42DD56BE",
"pparameter":
{
"parameterId": "TargetVersion",
"value": {
"memberIds": [
"public.Actual"
],
"hierarchyId": ""
}
}
}
In “monitor – Process and Workflows”, you can view the status of process:
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 24/26
1/11/24, 7:31 PM Introduction of SAC Multi-actions Public API | SAP Blogs
(end)
Alert Moderator
Assigned Tags
Related Questions
How to learn SAP SAC being a SAP FICO consultant and having no engineering or technical backgroud
By Sanjay Kumar Lal Jul 27, 2023
SAC Multi Action API Step integration with BW/4HANA or BPC Embedded
By Jordan Senior Jul 26, 2023
Find us on
Newsletter Support
https://blogs.sap.com/2023/09/08/introduction-of-sac-multi-actions-public-api/ 26/26