Skip to content

Samples for Storage Service

Note

In most mobile applications, the configuration used in the Application Storage is used as the default settings, and the end users can customize the settings in the User Storage or Device Storage level in order to provide personalized settings for the user or device. In such cases in order to make sure that only the Administrator can modify the Application Storage configuration and other users can only view it (by Application Storage Runtime API or user/device Storage Runtime API with "overwrite=true" query parameter), the application storage configuration can be configured with empty ReadRoles and Administrator WriteRoles.

The application storage configuration HomeScreen is created for application mobileApp:

{
 "ApplicationId": "mobileApp",
 "HomeScreen": {
  "Menu": {
   "AutoHiding": false,
   "Style": "blue",
   "AutoHiding@odata.type": "Edm.Boolean",
   "Style@odata.type": "Edm.String"
  },
  "ShortCuts": ["Overview", "Profile"],
  "__metadata": {
   "ReadRoles": [],
   "WriteRoles": ["Administrator"]
  },
  "Menu@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject",
  "ShortCuts@odata.type": "Collection(Edm.String)",
  "__metadata@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageMetadata"
 },
 "HomeScreen@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject"
}

Only users with the Administrator role can modify these settings using Runtime API, but all other users can get these settings.

Then, the mobile application can get the settings on the device using https://<mobile services host>/mobileservices/application/mobileApp/Storage/v1/runtime/application/mobileApp/device/mydevice/HomeScreen?overwrite=true and fill the screen with values you received. The response body looks like:

{
 "Menu": {
  "AutoHiding": false,
  "Style": "blue"
 },
 "ShortCuts": ["Overview", "Profile"]
}

Assume the user configures the Menu/AutoHiding property value to true at device level:

PATCH https://<mobile services host>/mobileservices/application/mobileApp/Storage/v1/runtime/application/mobileApp/device/mydevice/HomeScreen

body:

{
 "Menu": {
  "AutoHiding": true
 }
}

The response body of https://<mobile services host>/mobileservices/application/mobileApp/Storage/v1/runtime/application/mobileApp/device/mydevice/HomeScreen?overwrite=true becomes:

{
 "Menu": {
  "AutoHiding": true,
  "Style": "blue"
 },
 "ShortCuts": ["Overview", "Profile"]
}

If you want to provide application level settings only to particular users and not all users (or settings provisioned in mobile app), then the ReadRoles can be defined, so that only users who have the Read role can get these settings.

For example, you want to provide a 2-factor authentication for managers to post some forms. Then another configuration "2factorAuth" can be defined for mobileApp application with specify ReadRoles to "Manager". Then, the whole application storage for mobileApp looks like:

{
 "ApplicationId": "mobileApp",
 "HomeScreen": {
  "Menu": {
   "AutoHiding": false,
   "Style": "blue",
   "AutoHiding@odata.type": "Edm.Boolean",
   "Style@odata.type": "Edm.String"
  },
  "ShortCuts": ["Overview", "Profile"],
  "__metadata": {
   "ReadRoles": [],
   "WriteRoles": ["Administrator"]
  },
  "Menu@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject",
  "ShortCuts@odata.type": "Collection(Edm.String)",
  "__metadata@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageMetadata"
 },
 "2factorAuth": {
  "RequestToken": {
   "url": "<https://2factor.server/requesttoken/phone>",
   "method": "POST",
   "parameters": ["username", "phone"]
  },
  "VerifyToken": {
   "url": "<https://2factor.server/verify>",
   "method": "POST",
   "parameters": ["token"]
  },
  "__metadata": {
   "ReadRoles": ["Manager"],
   "WriteRoles": ["Administrator"]
  },
  "RequsetToken@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject",
  "VerifyToken@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject",
  "__metadata@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageMetadata"
 },
 "HomeScreen@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject",
 "2factorAuth@odata.type": "#com.sap.mobile.server.storage.admin.v1.StorageObject"
}

Then, the https://<mobile services host>/mobileservices/application/mobileApp/Storage/v1/runtime/application/mobileApp/device/mydevice/2factorAuth?overwrite=true can return settings according to the login user's role, and mobile app can show screens and control flows according to the 2factorAuth settings.

The Application Storage configuration can also be used to persist settings for server application, if both ReadRoles and WriteRoles are defined as a role (or roles) which never belong to any users. Then, your server application can read/write these application storage configuration using a technical user who has the role.

Storage service supports two type of APIs:

  • Admin APIs

  • Runtime APIs


Last update: August 12, 2020