Skip to Content
Technical Articles
Author's profile photo Marc Huber

Getting BTP user information in AppGyver

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%20classic%20data%20entity%20-%20REST%20API

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%20Record%20%28GET%29

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%20schema%20properties

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%20variable%20userApi

data variable userApi

         3. Display the user information

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

Bind%20text%20field%20to%20data%20variable

Bind text field to data variable

 

Final result

Assigned Tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Daniel Wroblewski
      Daniel Wroblewski

      This is nice ... thanks for adding ... works like a charm

      Author's profile photo Daniel Wroblewski
      Daniel Wroblewski

      What is scopes for? I didn't get anything returned.

      Author's profile photo Marc Huber
      Marc Huber
      Blog Post Author

      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)."

      Author's profile photo aruljoth arumugam
      aruljoth arumugam

      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

      Author's profile photo Boo Siong Khoo
      Boo Siong Khoo

      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.

      Author's profile photo Marc Huber
      Marc Huber
      Blog Post Author

      Hi Boo Siong Khoo ,

       

      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

      Author's profile photo Daniel Wroblewski
      Daniel Wroblewski

      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
      Author's profile photo Vikash Kumar
      Vikash Kumar

      Hi Daniel,

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

      Thanks,

      Vik

       

       

      Author's profile photo Daniel Wroblewski
      Daniel Wroblewski

      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)

      Author's profile photo Vikash Kumar
      Vikash Kumar

      Thanks Daniel!

      Author's profile photo Derrick Chuah
      Derrick Chuah

      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="/_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-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>
      Author's profile photo Jay Adnure
      Jay Adnure

      Hi @Derrick Chuah did you find any fix on this?

      Author's profile photo Derrick Chuah
      Derrick Chuah

      Yes, you can only get response (user api) to deployed app, not in SAP build.

      Author's profile photo Jay Adnure
      Jay Adnure

      So if deploy the above app as is should work without any dependency?

      Author's profile photo Derrick Chuah
      Derrick Chuah

      Yes correct : ) at least that's work for me.

      Author's profile photo ANIKET NARENDRA PATIL
      ANIKET NARENDRA PATIL

      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