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: 
MarcHuber
Product and Topic Expert
Product and Topic Expert
3,960
Introduction

Are you using the BTP Authentication feature in your AppGyver app and you want to know who is using the application?

In this guide I will explain quickly how to get the logged-in user information as email, first name or last name.

Steps

  1. Create a REST API data source

  2. Define a data variable

  3. Display user data


 

  1. Create a REST API data source


Go to the DATA tab and create an AppGyver classic data entity ->  REST API direct integration.

Call the data source userApi


AppGyver classic data entity - REST API


Set the settings to:

Resource ID: userAPI

Resource URL: user-api/currentUser


BASE userApi


 

Define the GET RECORD (GET) without an URL Placeholder and remove the /{id} from the Relative path.


get Record (GET)


Go to the SCHEMA Tab and create the following schema by clicking ADD Property.

You need displayName, email, firstname, lastname, name all type of text. Additionally you need scopes as list of texts.


Add schema properties


 

          2. Define a data variable

Add a new data variable for the userAPI as data variable type “Single data record” and modify the logic that it just get the records and set the data variable. Remove the delay part.


data variable userApi


         3. Display the user information

Now you can use the data variable userApi to display the logged-in user information.


Bind text field to data variable


 

Final result

20 Comments
Dan_Wroblewski
Developer Advocate
Developer Advocate
This is nice ... thanks for adding ... works like a charm

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos
What is scopes for? I didn't get anything returned.
MarcHuber
Product and Topic Expert
Product and Topic Expert
0 Kudos
I found this in the documentation of the api. Scopes are related to the permissions a user needs to access a resource. This property holds the required scopes to access the target path. Access is granted if the user has at least one of the listed scopes. Note: Scopes are defined as part of the xsuaa service instance configuration. You can use ias as authenticationType and xsuaa scopes for authorization if the application router is bound to both (ias and xsuaa)."
aaruljothi
Participant
0 Kudos
Hi Marc,

We spoke about this as a limitation early this month during the BTP workshop but delighted to see it no more a limitation. I will try this and let you know.

 

Regards,

Aruljothi Arumugam
BSKhoo
Explorer
0 Kudos
Hi,

 

I am having issue retrieving BTP user information after the app has been deployed to appgyverapp.black or BTP. user-api path shows Error 404 not found if I launch it from appgyverapp.black domain or BTP as HTML5 Application.

 

Thanks.
MarcHuber
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi boosiong ,

 

can you try to use as a Resource URL: user-api/currentUser without the "/" before user-api.

I just updated the blog to it.

 

Best regards,

Marc
Dan_Wroblewski
Developer Advocate
Developer Advocate
I am trying to get the user information in the new SAP Build Apps version and am having trouble (just in preview). It works perfectly in the old SAP AppGyver version but not the new one. Is this a known issue or am I doing something wrong. I tried without / but that removed the error but it returned HTML:
{"text_response":"<!DOCTYPE html><html lang=\"en\" style=\"scroll-behavior:smooth\"><head><meta charSet=\"utf-8\"/><meta name=\"viewport\" content=\"width=device-width\"/><meta name=\"next-head-count\" content=\"2\"/><script type=\"text/javascript\" src=\"/nodered.min.js\"></script><script>var exports = {\"__esModule\": true};</script><script>window.sapXsuaa = true;</script><meta name=\"ag-preview-csrf-token\" content=\"cbebc0360b4304ea-0N_utRvzN-v24jqOvIHg6aHsWqQ\"/><link rel=\"preload\" href=\"/_next/static/css/1b40617456acbe9e.css\" as=\"style\"/><link rel=\"stylesheet\" href=\"/_next/static/css/1b40617456acbe9e.css\" data-n-g=\"\"/><noscript data-n-css=\"\"></noscript><script defer=\"\" nomodule=\"\" src=\"/_next/static/chunks/polyfills-5cd94c89d3acac5f.js\"></script><script src=\"/_next/static/chunks/webpack-52c544795b589ebf.js\" defer=\"\"></script><script src=\"/_next/static/chunks/framework-d341a4038e4a0533.js\" defer=\"\"></script><script src=\"/_next/static/chunks/main-e1de8eb596b858d7.js\" defer=\"\"></script><script src=\"/_next/static/chunks/pages/_app-fb2460cac90a17f4.js\" defer=\"\"></script><script src=\"/_next/static/chunks/pages/%5BappId%5D/%5BappName%5D/%5B...params%5D-f916b24560e27b43.js\" defer=\"\"></script><script src=\"/_next/static/ylIjcEyAeAguBHUmII1Zj/_buildManifest.js\" defer=\"\"></script><script src=\"/_next/static/ylIjcEyAeAguBHUmII1Zj/_ssgManifest.js\" defer=\"\"></script><script src=\"/_next/static/ylIjcEyAeAguBHUmII1Zj/_middlewareManifest.js\" defer=\"\"></script><style id=\"jss-server-side\"></style></head><div id=\"__next\" data-reactroot=\"\"><div class=\"css-1dbjc4n r-1awozwy r-1777fci r-u8s1d\" style=\"bottom:0px;left:0px;right:0px;top:0px\"><div class=\"css-1dbjc4n\"></div></div></div><script id=\"__NEXT_DATA__\" type=\"application/json\">{\"props\":{\"isServerSideRendered\":true},\"page\":\"/[appId]/[appName]/[...params]\",\"query\":{\"appId\":\"102\",\"appName\":\"fun-days-2\",\"params\":[\"user-api\",\"currentUser\"]},\"buildId\":\"ylIjcEyAeAguBHUmII1Zj\",\"isFallback\":false,\"appGip\":true,\"scriptLoader\":[]}</script></html>"}

OK
derrick_5988
Discoverer

do I have to deploy app to BTP only can return user detail with user api or inside sap build will do? I've followed your guide but I couldn't get anything in sap build.






However, i'm getting status code 200 and the response is this:
<!DOCTYPE html><html lang="en" style="scroll-behavior:smooth"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><script type="text/javascript" src="/nodered.min.js"></script><script>var exports = {"__esModule": true};</script><script>window.sapXsuaa = true;</script><meta name="ag-preview-csrf-token" content="c79bce15eab8e67a-N3fyAwaMNGsEiJsfpDil0SGlIC8"/><link rel="preload" href="https://blogs.sap.com/_next/static/css/1b40617456acbe9e.css" as="style"/><link rel="stylesheet" href="https://blogs.sap.com/_next/static/css/1b40617456acbe9e.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-5cd94c89d3acac5f.js"></script><script src="/_next/static/chunks/webpack-52c544795b589ebf.js" defer=""></script><script src="/_next/static/chunks/framework-d341a4038e4a0533.js" defer=""></script><script src="/_next/static/chunks/main-e1de8eb596b858d7.js" defer=""></script><script src="/_next/static/chunks/pages/_app-53561cdd60256e6a.js" defer=""></script><script src="/_next/static/chunks/pages/%5BappId%5D/%5BappName%5D/%5B...params%5D-f916b24560e27b43.js" defer=""></script><script src="/_next/static/hwmQ0Y1XFfYW1heKmNj_x/_buildManifest.js" defer=""></script><script src="/_next/static/hwmQ0Y1XFfYW1heKmNj_x/_ssgManifest.js" defer=""></script><script src="/_next/static/hwmQ0Y1XFfYW1heKmNj_x/_middlewareManifest.js" defer=""></script><style id="jss-server-side"></style></head><div id="__next" data-reactroot=""><div class="css-1dbjc4n r-1awozwy r-1777fci r-u8s1d" style="bottom:0px;left:0px;right:0px;top:0px"><div class="css-1dbjc4n"></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"isServerSideRendered":true},"page":"/[appId]/[appName]/[...params]","query":{"appId":"33","appName":"staffing-board","params":["user-api","currentUser"]},"buildId":"hwmQ0Y1XFfYW1heKmNj_x","isFallback":false,"appGip":true,"scriptLoader":[]}</script></html>
modish
Explorer
0 Kudos

Hi Daniel,

I am also getting the same issue. Did you get any solution for this?

Thanks,

Vik

 

 

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos
I believe this relates to the fact that you must deploy an IAS tenant, and it no longer works because of that. I assume they are working to bring this back (technically, I'm not sure this feature was officially rolled out)
modish
Explorer
0 Kudos
Thanks Daniel!
Jay2
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi @derrick_5988 did you find any fix on this?
derrick_5988
Discoverer
0 Kudos
Yes, you can only get response (user api) to deployed app, not in SAP build.
Jay2
Product and Topic Expert
Product and Topic Expert
0 Kudos
So if deploy the above app as is should work without any dependency?
derrick_5988
Discoverer
0 Kudos
Yes correct : ) at least that's work for me.
aniketnpatil
Advisor
Advisor
0 Kudos

Hello,

use the "/" before the user-api/CurrentUser and you can access the user details (even in Build Apps Preview) 🙂

Resource URL: /user-api/currentUser

MarcHuber
Product and Topic Expert
Product and Topic Expert

Quick Update:

In SAP Build Apps you don't need a REST API anymore to access the user information. You can directly use the formulas systemVars.currentuser:

Best regards,
Marc

Isyraf_Afifi
Explorer
0 Kudos

Hi @MarcHuber 

Can we get a list of user in SAP BTP to build apps?

Best regards, Isyraf

RamaniNagarajan
Explorer
0 Kudos

Hi @MarcHuber 

I need to run a webservice directly from JavaScript of Build Apps, which I am able to do in B/Process Automation.  May I know how to do it?  I have raised a query also regarding this, please.

https://community.sap.com/t5/technology-q-a/how-to-call-webservice-using-javascript-of-appgiver-with... 

 

Thanks, Ramani Nagarajan

 

HarikumarA
Associate
Associate
0 Kudos

Use delay component and loop it till the systemVariable user infomation is available.