Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
lalitmohan
Product and Topic Expert
Product and Topic Expert
10,160

SAP Datasphere and its open data ecosystem  is the foundation for a business data fabric. It equips any organization to deliver meaningful data to every data consumer with business context and logic intact.

In addition to enabling live connections from SAP Analytics Cloud and its Microsoft Office Add-In, it's also designed to enable customers to establish connections via an OData API with any analytical frontend solution. You can connect to the OData API and consume data exposed as views or analytic models in different clients, tools, and apps that are capable of authenticating via an OAuth client and accessing an OData service.

1.png

You can read and understand more about SAP Datasphere OData API in the following links:

In this blog post, you will understand how to consume data exposed as views or analytic model to rest clients via the OData API using OAuth2.0 flow with type authorization_code.

To follow this article, You need to have a SAP BTP global account set up to be entitled to the SAP Datasphere. Please follow the excellent blog on How to create an SAP Datasphere service instance in the SAP BTP Platform.

Before you start, ensure you have set up and launched the SAP Datasphere service instance; if not, Go to your subaccount space then the services Instance page, search for "Datasphere", and click on the three dots(…) on the rightmost side with Datasphere instance and then View Dashboard. OR Look for the URL to the newly created SAP Datasphere tenant in the email.

As a pre-requisite, a basic understanding of SAP Datasphere will be good but in-case you missed out on it, you can enjoy a free self-paced learning journey Explore SAP Datasphere on SAP Learning.

Let's get Started.

Create OAuth2.0 Client in SAP Datasphere

For consuming exposed data in third-party clients, tools, and apps via OData service requires OAuth2.0 clients. Follow the steps mentioned below to create OAuth2.0 client.

1. In the side navigation area, click System -> Administration2.png

2. Under App Integration, select Add a New OAuth Client.3.png

3. In the dialog, add a Name for the OAuth client. From the Purpose list, select Interactive Usage and enter a Redirect URI to indicate where you want redirected after authorization. Select Add4.png

4. Once the OAuth Client is created, click on the edit icon to get your client ID and secret then click on Done.5.png

5. Now at last copy the OAuth2SAML Audience and your Datasphere URL.6.png

Set up a REST Client Script

Visual Studio Code (or just VSCODE) is a free source code editor developed and maintained by Microsoft. The REST Client extension allows you to send HTTP requests and view the response in VSCODE directly.

You are going the use this REST Client to query the OData API endpoints in order to understand the OAuth2.0 flow.

  1. Open Visual Studio Code and
  2. create a file with name ds-api.http Or you can give any name but file extension should be .http Or .rest. 
  3. Copy the below code to the file.

 

 

 

###
@auth-url = <enter the OAuth2SAML Audience>
@your-client_id = <enter generated OAuth Client ID>
@your-client_secret = <enter Security Secret>
@hostname = <enter SAP Datasphere Tenant URL>​

 

 

Replace the placeholder as per your OAuth Configured Client : OAuth2SAML Audience, OAuth Client ID, Security Secret and SAP Datasphere host URI you have generated in previous step.

 

Generate Code Grant token

To consume the exposed data in third-party clients requires an OAuth2.0 flow with type authorization_code. Users must manually authenticate against the configured IDP to generate the authorization code before continuing with the remaining OAuth2.0 steps. Follow the steps listed below to generate it easily.

1. Copy the below code to the file.

 

 

 

### Right click on the below URL and select Generate code snippet
### then select Shell
{{auth-url}}/oauth/authorize?response_type=code&client_id={{your-client_id}}

 

 

 

2. Right click on the below URL and select Generate code snippet.7.png

3. Select Shell then HTTPie. It will generate the Encoded URL. Copy the URL:8.png

4. On a browser, open the URL:9.png

5. As a result of your access it will redirect you to a page where you should get the code value presented in the query parameters, copy that value (e.g. lxuC1347ZLcNg3gjqFHKjAc6gT4iB0hp)10.png6. Create a variable code with the value you have copied in the last step:

 

 

 

### variable to store authorization code
@code = edF5BQ5vVsAqpkljF2tk1qqgnW4C7JRm

 

 

 

11.png

Obtain an Access Token

The Oauth2 service generates access tokens for authenticated applications. The token returned in the Oauth2 response can be used to access protected resources on OData services.

Copy below code just below the above code to Obtain a access Token and store it to a variable:

 

 

 

### Obtain an Access Token
# @name accessTokenCall
POST {{auth-url}}/oauth/token
Authorization: Basic {{your-client_id}} {{your-client_secret}}
Content-Type: application/x-www-form-urlencoded

code={{code}}
&grant_type=authorization_code

###
@accessToken = {{accessTokenCall.response.body.access_token}}

 

 

 

12.png

Retrieve Space and Asset Data 

Now you can compose your OData request based on your SAP Datasphere tenant URL in the following format: 

  • https://<tenant_url>/api/v1/dwc/<request> OR 
  • https://<tenant_url>/dwaas-core/odata/v4/<request>

and Use the catalog request to list spaces and assets that are exposed for consumption. Read more to compose your OData request. 

To list all the spaces you have access to, enter:

 

 

 

### List all the spaces
# @name listAllSpaces
GET {{hostname}}/api/v1/dwc/catalog/spaces
Authorization: Bearer {{accessToken}}
Accept: application/json

 

 

 

 To list all the assets you have access to, enter:

 

 

 

### List all the assets
# @name listAllAssets
GET {{hostname}}/api/v1/dwc/catalog/assets
Authorization: Bearer {{accessToken}}
Accept: application/json 

 

 

 

13.png

Summary

So, now you have understood how to connect to the OData API and consume data exposed as views in a rest client by accessing the OData services and authenticating them via an OAuth client.

What’s next?

In the next blog post, we will see how to consume the exposed data via OData API in custom build analytical frontend solution. 
Keep your anticipation high for the upcoming blog posts. Stay curious!

Reference & Further Reading

SAP Datasphere Features
SAP Datasphere Power Of Business Data
Start your SAP Datasphere guided experience 
SAP Datasphere: Unleash the power of business data.
What is SAP Datasphere and what benefits does it bring to your business?
Unlock the full potential of your enterprise data with SAP Datasphere Catalog

For more information and related blog posts on the topic page for SAP Datasphere. If you have questions about SAP Datasphere you can submit them in the Q&A area for SAP Datasphere in the SAP Community.

Find out how to unleash the power of your business data with SAP’s free learning content on SAP Datasphere. It’s designed to help you enrich your data projects, simplify the data landscape, and make the most out of your investment. Check out even more role-based learning resources and opportunities to get certified in one place on  SAP Learning site.

13 Comments
TuncayKaraca
Active Contributor

Hello @lalitmohan,

It's good to see how SAP Datasphere's OData API's used with Visual Studio Code. Indeed OData API of Datasphere is a very powerful feature! Thanks for sharing. 

BTW - SAP Datasphere: Overview and Architecture link is broken! 

TuncayKaraca_0-1708098332215.png

Regards,
Tuncay

lalitmohan
Product and Topic Expert
Product and Topic Expert

Hello Tuncay,

Thanks for your comments and yes it is a very powerful feature. I got this query several times in my sessions so thought to write it.
Appreciate your observation, I have updated the References and further readings.

Regards, Lalit 

 

MKYap
Discoverer
0 Kudos

Hello Lalit, 

We have understood that SAP Datasphere itself doesn't directly accept data being "pushed" to it.

Do you have somewhere in the roadmap where it would be possible to push data from S/4 HANA On Premise to SAP Datasphere?

Thanks,

MK

Harshal22
Discoverer

Hi @lalitmohan 

Very informative post. 

We want to consume Data Exposed by SAP Datasphere (views) via OData API in freestyle Fiori application which will be deployed on BTP.

As OAuth Authorization Code Authentication is not yet available for destination configuration via the cockpit. What would be the best approach for above requirement?

Thanks,

Harshal

 

David_Coiro
Explorer
0 Kudos

Hi @Harshal22 i´m facing the same problem ... have you been able to solve it ?. Thanks all !

Harshal22
Discoverer
0 Kudos

Hi @David_Coiro 

Not yet, still facing same problem.

@lalitmohan - can you please help us here.

Thanks ,

Harshal N

 

TuncayKaraca
Active Contributor
0 Kudos

@MKYap You should use Connections and Acquiring Data in the Data Builder options in SAP Datasphere for "push data from S/4 HANA On Premise to SAP Datasphere"

Harshal22
Discoverer
0 Kudos

Hi @TuncayKaraca 

Is it also possible to push data back from SAP Datasphere to S/4 HANA on premise or SAP BW/4HANA.

Regard's,

Harshal N

Swetha__Balusamy
Explorer

Hi @lalitmohan ,

We have a scenario where we want to consume the SAP Datasphere APIs in the SAP BTP CAP Application as an ODATA service. We created an OAuth2.0 client like its mentioned in your blog. But there is a step in which it is mentioned that "To consume the exposed data in third-party clients requires an OAuth2.0 flow with type authorization_code. Users must manually authenticate against the configured IDP to generate the authorization code" 

We want to use the API in a system to system communication( from SAP Data Sphere to SAP CAP application) where in there wont be any UI screens involved. Can you please help us understand how to make this system to system call without UI interaction.?

Irfan098
Explorer

Hi 
I am trying to create a python script to connect with Datasphere and pull data using the ODATA api and write to a blob storage. There is very little documentation for these kind of cases.

However, when creating the oauth2.0 client, i am not sure what should be the 'callback uri' .
At the moment, i tried to keep it localhost, but the issue is i dont get back the new token. 

Would appreciate if you could give your guidance.

Jorge_Martinez
Explorer
0 Kudos

@Irfan098 You can try with "https://oauth.pstmn.io/v1/callback" as callback uri, it worked for me.

Irfan098
Explorer
0 Kudos

thank you @Jorge_Martinez. I was able to use this uri: https://oauth.powerbi.com/views/oauthredirect.html

Following this  PRESSEMITTEILUNG paper.

 

The only drawback is we have to renew the refresh token after every 180 days.

A_Karthik
Newcomer
0 Kudos

Can we trigger a task chain sap datasphere using python?