Our modern data landscapes thrive on automation. In this post, we’ll walk end-to-end through a real-life integration scenario that tackles one of the building blocks in this context:
Starting a SAP Datasphere Task Chain remotely from SAP BTP ABAP Cloud using OAuth 2.0 Client Credentials and the Datasphere Task Chain REST API
The goal is to orchestrate Datasphere data processing flows directly from ABAP Cloud — securely, programmatically, and fully automated.
We will cover the below points:
- Creating a Task Chain in Datasphere
- Configuring OAuth clients in Datasphere
- Setting up Communication System & Arrangement in ABAP Cloud
- Executing the Task Chain remotely: Consume REST API from ABAP Cloud
1 Architecture Overview
ABAP Cloud Task Chain Execution: ABAP Cloud acts as the caller. Datasphere exposes the Task Chain API protected by OAuth.
2 Prerequisites
You must have:
- SAP Datasphere tenant with developer + admin access
- A Task Chain to trigger
- SAP BTP ABAP Environment (ABAP Cloud) with developer access
- BTP ABAP: Authorization to configure OAuth clients and Communication Arrangements
3 Creating a Task Chain in SAP Datasphere
The first step is defining a Task Chain that encapsulates the processing logic you want to execute remotely.
In the given example:
- The Task Chain starts with a Begin node
- Executes a Replication Flow for loading dimension data
- (Can be extended with transformations, views, or further flows)
Main takeaways:
- Task Chain must be Deployed
- Note the Technical Name (used later by API)
- Verify it runs manually before you automate via the API
4 Configuring OAuth Client in SAP Datasphere
To allow ABAP Cloud to call Datasphere APIs securely, we create an OAuth Client in Datasphere Administration.
Navigation Path
Datasphere → Administration → App Integration → OAuth Clients
OAuth Endpoints Provided
Amongst others, SAP Datasphere automatically exposes:
- Authorization URL
- Token URL
These are required for OAuth2 token retrieval. Moreover you must create a technical user that has access to the Datasphere space and is able to run the task chains that are in scope. Typically this is done by assigning a scoped role.
Configured OAuth Client (based on Technical User)
This is where you see the OAuth Client specific URLs - take note of them for later configuration in ABAP BTP:
Your specific OAuth client for consumption from ABAP BTP. The secret key is only shown once upon creation - keep this in mind!
Important settings:
Parameter | Value |
Grant Type | Client Credentials |
Purpose | Technical User |
Roles | space access must be given (e.g. by scope role in DSP) |
Token Lifetime | e.g. 60 minutes |
Save the Client ID and Client Secret — this is used in ABAP Cloud later on.
5 Creating Communication Artifacts in ABAP Cloud
Now we configure the outbound technical connection from ABAP Cloud to Datasphere.
First create an Outbound Service of type HTTP:
Create a Communication Scenario with Authentication Methods = OAuth 2.0 only, bind it to your outbound service and publish it:
Navigation: ABAP Environment Web Access → Communication Management → Communication Systems
The hostname is your Datasphere tenant URL. Outbound OAuth URLs (like Token/Authentication) can be found on the Datasphere side under Administration -> App Integration (previous step).
You have to add a user "OAuth 2.0 (Basic)":
Key fields:
Field | Example |
System ID | DSP_REST |
Host Name | <your-datasphere-host> (tenant URL) |
Port | 443 |
OAuth 2.0 Endpoints | From Datasphere for Token & Authorization URL (Audience URL not required) |
Client ID | Datasphere OAuth Client ID |
Client Secret | Datasphere Secret (you must take note of this when creating the OAuth Client) |
6 Creating a Communication Arrangement in SAP ABAP Cloud
Now we bind the Communication System to a Communication Scenario that allows REST calls.
Navigation: Communication Management → Communication Arrangements
Arrangement Example: ZDSP_CS_REST
Note the service path: The dynamic parts of the path are set from ABAP (this is to keep the space + task chain flexible and controllable from the actual caller: ABAP).
What this provides:
- Preconfigured service URL
- OAuth token handling by ABAP runtime
- Secure outbound API consumption
7 Calling the Datasphere Task Chain API from ABAP Cloud
Now comes the fun part: consuming the REST API. Datasphere exposes endpoints such as:
- POST /api/v1/datasphere/tasks/chains/<space_id>/run/<task_chain_technical_name>
- GET /api/v1/datasphere/tasks/logs/<space_id>/<log_id>
Which triggers a new execution or reads the status of a task chain run.
ABAP Cloud Implementation Pattern
In ABAP Cloud when working with REST API to integrate external services, you typically:
- Create HTTP destination automatically from the created Communication Arrangement
- Use CL_WEB_HTTP_CLIENT_MANAGER
- Perform POST/GET requests
- Parse response (run ID, status)
The code snippet performs the following parts in more detail:
- Run as a class-run program (IF_OO_ADT_CLASSRUN) -> you can execute directly from ADT and print to the console.
- Locate the configured Communication Arrangement (bound to our Communication System DSP_REST) using CL_COM_ARRANGEMENT_FACTORY.
- Create an HTTP destination from the Communication Arrangement using CL_HTTP_DESTINATION_PROVIDER=>CREATE_BY_COMM_ARRANGEMENT.
- Create an HTTP client from the destination (CL_WEB_HTTP_CLIENT_MANAGER).
- POST request to the Task Chain “run” endpoint:
- triggers a new run
- receives a JSON response containing a LogId
- WAIT a few seconds.
- GET the log endpoint using the returned LogId:
- retrieves the execution status (RUNNING, later SUCCESS / FAILED, etc.)
- Print everything in the ABAP Console.
ABAP-Code Snippet:
CLASS zcl_dsp_rest_api DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
CLASS-DATA:
out TYPE REF TO if_oo_adt_classrun_out.
CLASS-METHODS:
call_dsp
RAISING
cx_http_dest_provider_error
cx_web_http_client_error.
ENDCLASS.
CLASS zcl_dsp_rest_api IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
zcl_dsp_rest_api=>out = out.
TRY.
call_dsp( ).
CATCH cx_web_http_client_error
cx_http_dest_provider_error INTO DATA(exception).
out->write( exception->get_text( ) ).
ENDTRY.
ENDMETHOD.
METHOD call_dsp.
TYPES: BEGIN OF ty_log,
logId TYPE i,
END OF ty_log.
DATA: ls_log TYPE ty_log.
DATA(communication_system) = 'DSP_REST'.
DATA(arrangement_factory) = cl_com_arrangement_factory=>create_instance( ).
DATA(comm_arrangement_range) = VALUE if_com_arrangement_factory=>ty_query-cs_id_range(
( sign = 'I' option = 'EQ' low = communication_system ) ).
arrangement_factory->query_ca(
EXPORTING
is_query = VALUE #( cs_id_range = comm_arrangement_range )
IMPORTING
et_com_arrangement = DATA(arrangements) ).
DATA(arrangement) = arrangements[ 1 ].
DATA(destination) = cl_http_destination_provider=>create_by_comm_arrangement(
comm_scenario = 'ZDSP_CS_REST'
service_id = 'ZDSP_REST_SRV_REST'
comm_system_id = arrangement->get_comm_system_id( ) ).
DATA(http_client) = cl_web_http_client_manager=>create_by_http_destination( destination ).
DATA(request) = http_client->get_http_request( ).
request->set_uri_path( '/chains/BDCPOC/run/TC_DIM2_A001' ).
DATA(response) = http_client->execute( if_web_http_client=>post ).
CALL METHOD /ui2/cl_json=>deserialize
EXPORTING
json = response->get_text( )
CHANGING
data = ls_log.
data(log_str) = CONV string( ls_log-logId ).
out->write( 'Task Chain started. LogId created:' && log_str ).
WAIT UP TO 10 SECONDS.
CONCATENATE '/logs/BDCPOC/' log_str INTO DATA(uri).
clear: request, response, http_client.
http_client = cl_web_http_client_manager=>create_by_http_destination( destination ).
request = http_client->get_http_request( ).
request->set_uri_path( uri ).
response = http_client->execute( if_web_http_client=>get ).
out->write( 'Task Chain Log REST API - via GET - Task Chain Status:' && response->get_text( ) ).
ENDMETHOD.
ENDCLASS.Once triggered:
- Datasphere creates a new Task Chain run
- Execution can be monitored in Datasphere UI
- API returns run ID and status
Follow-up calls can fetch:
- Execution status
- Logs
- Completion result
8 Execution Results
The Task Chain in Datasphere is in Running status:
9 Conclusion/Outlook & Further aspects:
Overview of the major building blocks:
Capability | Result |
Secure Auth | OAuth 2.0 Client Credentials |
No hardcoded secrets | via Communication Arrangements/System |
Remote orchestration | Creating an end-to-end orchestrated chain of tasks |
Cloud-native ABAP | Using appropriate ABAP Class APIs |
Datasphere automation | Using Task Chain API |
Use Cases that the implementation enables:
- Nightly batch orchestration
- Event-driven data loads
- Cross-system workflows (this was our ultimate focus)
- CI/CD data pipelines
- API-driven analytical data refresh
References
- SAP Datasphere Task Chain API Documentation: https://api.sap.com/api/DatasphereTasks/overview
- SAP Datasphere Task Chain Help Page: https://help.sap.com/docs/SAP_DATASPHERE/c8a54ee704e94e15926551293243fd1d/274f2736465c4c48a091c67588...
- ABAP Cloud - how to call external APIs: https://jacekw.dev/blog/2022/oauth-client-credentials-from-abap-cloud/
These are your main takeaways to further sharpen the solution:
- Use short token lifetimes
- Separate technical OAuth users
- Monitor task runs via API from ABAP
- Handle retries & failures in ABAP
- Log run IDs for observability
This blog entry complements my other blog on Start remote Process/Actions in BTP ABAP via Task Chains from SAP Datasphere
If you have any aspects, comments and/or concerns, please raise them and let's discuss. I'm happy and proud that this article was written by at least 90% human and only 10% AI 🙂