The User API service provides an API to query the details of the user that is currently logged on to the HTML5 application.
SAP Business Technology Platform, Neo environment will sunset on December 31, 2028, subject to terms of customer or partner contracts.
For more information, see SAP Note 3351844.
This documentation refers to SAP Business Technology Platform, Neo environment. If you are looking for documentation about other environments, see SAP Business Technology Platform
↗️ .
If you use a corporate identity provider (IdP), some features of the API do not work as described here. The corporate IdP requires you to configure a mapping from your IdP’s assertion attributes to the principal attributes usable in SAP BTP. See Configure User Attribute Mappings.
To use the User API in your HTML5 application, add a route to your neo-app.json
application descriptor file as follows:
...
"routes": [
{
"path": "<application path to be forwarded>",
"target": {
"type": "service",
"name": "userapi"
}
}
]
...
The route defines which requests to the application are forwarded to the API. The route is matched with the path from a request. All GET
requests with paths that start with the path
from the route are forwarded to the API.
With the following configuration, all
GET
requests with paths starting with/services/userapi
are forwarded to the user API.... "routes": [ { "path": "/services/userapi", "target": { "type": "service", "name": "userapi" } } ] ...
The User API supports the following endpoints:
-
/
currentUser
-
/
attributes
The User API requires authentication. The user is logged on automatically even if the authentication
property is set to none in the neo-app.json
file.
Calling the /currentUser
endpoint returns a JSON object that provides the user ID and additional information of the logged-on user. The table below describes the properties contained in the JSON object and specifies the principal attribute used to compute this information.
Property Name |
Description |
Principal Attribute |
---|---|---|
|
The user ID that is used for logging on. |
n.a. |
|
The first name of the user. |
firstname |
|
The last name of the user. |
lastname |
|
The email address of the user. |
|
|
Concatenated user name derived from the first name, last name, and user ID. If either the first or the last name does not exist, the |
firstname + lastname + name |
The /currentUser
endpoint maps a default set of attributes. To retrieve all attributes, use the /attributes
endpoint as described in User Attributes.
A sample URL for the route defined above would look like this:
/services/userapi/currentUser
.An example response could return the following user data:
{ "name": "p12345678", "firstName": "John", "lastName": "Doe", "email": "[email protected]", "displayName": "John Doe (p12345678)" }
Calls to this service must not be cached by the Content Delivery Network(CDN). Caching causes the wrong results to be returned.
The /attributes
endpoint returns the principal attributes of the current user as a JSON object. These attributes are received as SAML assertion attributes when the user logs on. To make them visible, define a mapping within the trust settings of the SAP BTP cockpit, see Configure User Attribute Mappings.
A sample URL for the route defined above would look like this:
/services/userapi/attributes
.If the principal attributes
firstname
,lastname
,companyname
, andorganization
are present, an example response may return the following user data:{ "firstname": "John", "lastname": "Doe", "companyname": "Doe Enterprise", "organization": "Customer sales and marketing" }
For some endpoints, you can use query parameters to influence the output behavior of the endpoint. The following table shows which parameters exist for the /attributes
endpoint and how they impact the outputs.
URL Parameter |
Type/Unit |
Default |
Recommended Value |
Behavior |
---|---|---|---|---|
|
Boolean |
false |
|
If set to
|