In this exercise we will build backend services with the SAP AppGyver. We will build three services:
- To store and read the warranty information
- To read registered products data from SAP Sales Cloud
- To create and read warranty subscription information for given account and registered product
After completion of this exercise, you would be familiar with
- Create backend project
- Creating database tables
- Perform CRUD operations on them using REST API
- Consuming external REST endpoints (like Sales Cloud OData API)
- Deploying and testing the service
Disclaimer: SAP AppGyver Cloud Composer (a.k.a. Cloud Integrations) featured in this session is a pre-released product and still under development. SAP reserves the right to make changes and set a future release date or not release it at all.
First you will need to go to Cloud Integrations builder from main SAP AppGyver view. We have pre-created and deployed an empty project for you so we'll get a running start for the workshop. You can create a new project yourself after the workshop steps.
- Login to backend if you haven't already
- https://platform.testgyver.com/auth/legacy
- Enter credentials from the Getting Started step
-
Once Backend is open you will see some basic information
- Name: Name is name of the backend service/application
- Hostname: This will be part of the API URL. Changing hostname will require removing existing deployment and deploying again so you should not change this during the workshop to avoid unnecessary wait time
Now we will proceed with creating database tables required for our backend services.
Since we are creating an application which would show the subscribed warranties, first we need a table to store warranty details like warranty terms.
After completing these steps you will have a table to store warranties.
- To create backend tables navigate to Data Tables options, Click on ADD NEW button. Provide a name to the table as
Warranties
- Configure Warranties table
Once the table is created an id
field is automatically added. This is the primary key to our database table and is a required property for creating new records. When we are creating new records to database then SAP AppGyver will automatically generate value for this id field.
Add an additional table field, named CoverageTerm
(1) as below and click plus icon (2):
- New field type is Text and it is required by default. Keep these values and click SAVE button (1) at top right corner as shown below:
- Scroll back up and click DATA BROWSER button
- Then create some warranties with coverage terms of your choosing. First time creation will take a while so wait for the blue Success message before creating another Warranty record:
- Success message should look like this:
- Create two or more warranties
- Close the Data Browser modal and scroll page down and click GENERATE ENDPOINT button
In the above section we have already created the database tables (Warranties) with some records and created Data Resource endpoint. Now we will test the auto-generated API for the first time.
-
Save the project from top right corner
-
Test the API in the browser (or postman)
- Get the URL from the corresponding data source and operation and test it either in a web-browser or postman
- You can see a glimpse the Logic Editor at the bottom of the screen. We'll come back to it later
- If you paste the URL to browser it will return a JSON response like this:
In the next step we need to implement an API to create, read, update and delete warranty description. However, before that we need an API to read registered products. We will read the registered producs from the SAP Sales Cloud system. However, we can't use the SAP Sales Cloud API directly in a AppGyver UI application directly due to CORS (Cross Origin Resource Sharing) issue. So, we need to wrap the SAP Sales Cloud API inside a AppGyver backend API. In this section we will do the same.
- Click BACK from left side menu and navigate to the EXTERNAL RESOURCES section to create a new OData Resource:
- Click ADD ODATARESOURCE button:
- Add following configuration to do discover available resources from SAP Sales Cloud API
- Choose
Basic Authentication
- Username
DISPLAY
- Password
ReadMe
- Base URL
https://my356925.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/
- Click VERIFY URL button and wait for a while
- You will see long list of available resources to make selection easier you can filter it
- Write 'RegisteredProductParty' to filter field (1) and toggle on 'RegisteredProductPartyInformationCollection' (2)
- Expand 'RegisteredProduct'
- You can test how the results look from TEST tab
- Click SAVE DATA RESOURCE after you've done the test
- Click GENERATE ENDPOINT to create Date Resource from OData API
- Save (1) and change output schemas:
- Navigate to the GET COLLECTION (1)
- Toggle off (2) to return specified properties
- Toggle every except 'RegisteredProductID' off (3)
- Scroll down to Logic Editor and double-click List Records block
- Click 'Authconfig' value bind button:
- Choose 'Object with properties':
- Choose 'Basic' authentication
- Click 'Username' value bind button
- Choose 'Static text'
- Repeat same for 'Password'
- Type
DISPLAY
to Username value - Type
ReadMe
to Password value - Click SAVE button to close the modal
- In the Logic Editor, click 'Send Successful Response' block and change response to a Formula:
MAP<Record>(outputs["List records"].records, { RegisteredProductID: Record.RegisteredProductID + ":" + Record.RegisteredProduct.SerialID })
- Click 'Response data' value bind button:
- Choose 'Formula'
- Click existing formula to edit it:
- Replace existing formula with a
MAP
formula from above in exercise:
- Save the project from top right corner and test new endpoint:
- Copy the URL from following location
- Ie.
https://<your unique hostname>.cm-backends.testgyver.com/api/v1/registeredproductpartyinformationcollection/
- You should see a lot of registered products with above mapping data
In the Exercise 1.2 we have already create a table to store Warranties and implemented an API to read from the table. In this section we will create a table to store the Warranty Subscriptions and API for list and create operations.
- To created backend tables navigate to Data Tables options, Click on ADD NEW. Provide a name to the table as 'WarrantySubscriptions'.
- Configure Warranty Subscription table
- Once the table is created, as we have seen earlier, an
id
field is automatically added, which will be the primary key to our database table - Add additional table fields as below:
Field name | Type | Description |
---|---|---|
IsActive | True/false | To check if the warranty is in active status or not |
Product | Text | To show the registered product description for selected account |
AccountID | Text | Account ID |
WarrantyEnd | Date text - ISO 8601 | Warranty expiry date information |
WarrantyID | Text | Warranty ID |
- Scroll down and “Add New Property” to add fields as shown below:
- Example of
IsActive
is given below:
- Please configure other fields in the same way
- Scroll to the bottom of the page and click GENERATE ENDPOINT button
-
Save project from top right corner
-
Choose GET COLLECTION from left side. Now it's time to familiarise ourselves with the Logic Editor
- Choose existing 'List Records' node (1) from the canvas and move it around freely
- Open 'Advanced' tab (2) from right side 'Properties' and rename node to 'List Subscriptions' (3)
- Drag new 'List Records' node under 'Data Tables' section to Logic Editor (1)
- Notice that left side menu also has 'List Records' under 'External Resources'! Use 'Data Tables' option instead
- Choose existing wires from 'List Subscriptions' to response nodes and delete them. Use Backspace key with Mac and Windows:
- Connect 'List Subscriptions' top output wire to new 'List Records' input (1)
- Connect new 'List Records' output wire to existing response nodes inputs (2, 3)
- Rename new 'List Records' to 'List Warranties' and make sure it is connected to 'Warranties' table (4, 5)
- Join Coverage Terms from Warranties to Warranty Subscriptions by using a mapping function in response node
- Click 'Send successful response' node and click 'Response data' value bind from Properties
- Choose 'Formula'
- Click existing formula to edit it:
- This Formula goes through each Warranty Subscriptions and finds a matching Warranty from Warranties
- It then adds
CoverageTerm
from the Warranty to output - Copy Formula to it's place:
MAP<Subscription>(outputs["List Subscriptions"].records, MERGE([Subscription, { CoverageTerm: FIND<Warranty>(outputs["List Warranties"].records, Warranty.id == Subscription.WarrantyID).CoverageTerm }]))
- Click SAVE
- Add
CoverageTerm
to the output schema
- Navigate back to BASE CONFIGURATION (1) and scroll to the bottom of the page
- Add new field called
CoverageTerm
(2) and click plus icon (3)
With this we have implemented Get Collection to get the list of warranty subscriptions. Now let us implement Create Warranty Subscription to create some records before testing it.
-
Save the project
-
To test go back to Data Resources and choose WarrantySubscriptions
- To test we need to use some tools that can post the data. In this workshop we will use Postman
- Run 'GET warranties' end point Exercise 1.2.2 to get some valid Warranty IDs. These will be used to create warranty-subscriptions
- Ie.
https://<your unique hostname>.cm-backends.testgyver.com/api/v1/warranties/
- Ie.
- Run 'POST warrantysubscriptions' end point and provide following payload
- Ie.
https://<your unique hostname>.cm-backends.testgyver.com/api/v1/warrantysubscriptions/
- Ie.
{
"Product": "1001",
"IsActive": true,
"AccountID": "1000034",
"WarrantyID": "<replace with an warranty-id in the previous step>",
"WarrantyEnd": "2021-11-16"
}
- Test 'GET warrantysubscription' end point by replacing POST with GET action in the URL bar.
In this section we have created three backend service APIs that will be used to build the user interface in the next section. We have built APIs based on the local storage as well as created wrapper API by consuming an external API (SAP Sales Cloud Registered Product).
Continue to - Exercise 2 - Building the UI with the SAP AppGyver Composer