Welcome to this series of hands-on tutorials from the SAP HANA Academy.
I'm Philip Mugglestone. In this series we're covering serverless functions in the SAP Business
Technology Platform. In this video tutorial we're going to see how we can access our serverless
function from SAP Build Apps. So we're going to build a UI with the no code SAP Build Apps,
but we're going to actually have some sales data that we're going to actually put into that UI,
and that's going to come via our serverless function and actually be actually getting
data out of SAP HANA Cloud. So let's just create ourselves a quick serverless function.
So for example we can call it sales. We'll use node.js. We're going to select yes to SAP HANA
Cloud and we're going to have authentication and authorization. Hit next. If we want we can just
go ahead and deploy the project directly. So it's scaffolded out the project just as we've seen
previously. So we'll just wait for that to deploy. Now whilst we're doing that we can actually just
go and have a quick look at SAP Build Apps. Now this is one I've got the free tier actually
installed and running here. If you want to learn how to actually get started with SAP Build Apps
then just go to the onboarding series from the SAP HANA Academy for SAP BTP and then you can find
there's a video tutorial showing you how to get up and running with SAP Build Apps. So let's go
ahead and launch it. Service has been created and if we now go to the discovery and network API
rules. Now the first thing we're going to need to do to make sure we can actually use this application
is to set up the necessary authorizations. So for that we'll go to security in the SAP BTP cockpit and
users and then you'll need to pick the user in the identity provider that you're using with SAP
SAP Build Apps. In that case it's my custom IAS tenant and I'm going to then assign the role collections
from my sales serverless function for admin and user. Up to you which actual scopes you would
actually assign through these role collections. Now if we just check we go actually and have a
look at the source code of our function we can see here that if we use the endpoint of sales then
they're going to need to have the user scope. Well we've assigned that so it should be fine. So let's
go back. Now there's one further thing we'll need to do. If we're going to work with this serverless
function from SAP Build Apps we're going to need to create a destination because we've got this
authentication to take care of. So we're going to need to build a destination so we can go to
connectivity and destinations and what we'll need to do is create a new destination. So we can give
it a name for example sales. We'll need to put in the URL and that's basically going to be this API
rule. So we'll copy that into here. We're going to specify authentication so for that one we're going
to specify it will be OAuth2JWTBearer and then we're going to need the client ID, the
client secret and the token URL. Seen in previous video tutorials we can get those for the UAA
service that we're using for this application by going to our secrets. So if you go to secrets
we've got our sales HDI binding secret but also our UAA binding secret. That is the one that I'm
interested in. If I decode I can see I've got my client ID. I'm going to copy and paste that in.
I'm going to need the token service URL so that's the URL here and I'm going to need to add
/oauth/token to the end and then I'm going to need the client secret. So that's
here. So I'm going to copy and paste that value in. Now we're also going to need to put some specific
settings in, some properties so that the build apps... We're also going to need to add some
additional properties so that build apps will recognize this as a destination it can use. So
one of them is going to be WebIDEEnabled. So we'll set that to true. A second one is going to be
HTML5.DynamicDestination. We'll set that to true and a third one that's not in the list
is AppgyverEnabled and again we need to set that one to true. Then we can save our destination.
If we want we can check the connection. It's normal that we're unauthorized because we haven't
provided a token but it looks to be well configured. So now we can go to SAP Build Apps
and actually try to make use of it. So let's go to SAP Build Apps and we'll create a new application,
a web and mobile application. We'll call it sales. Whatever you want. We'll hit create.
Now the first thing we need to do is to configure the authentication to SAP Business Technology
Platform. So we can do that from this authentication tab. We'll enable authentication
and we'll do it to SAP Business Technology Platform and confirm with OK.
And then we can go to the data. Now typically when you're working with OData services you can
add an integration to a SAP BTP destination. However this only works for OData services and actually
ours is a REST service. Our serverless function is not OData. So what we'll need to do is to use
the create data entity option and there we can choose SAP Business Technology Platform
destination REST API integration. And there we can give it a name for the resource and we can
choose our destination and we're going to choose the one called sales. Now if your destination
doesn't appear on this list it's probably because you've missed one of those additional properties.
We can give it a description as well, whatever you want. Now we need to make one little change here.
Actually it's got a common request header and just we need to delete that. So let's just remove this
common request header and save. Now we've got that we can go to list. We're going to be doing a list
so we'll activate that and then we need to give the path. Well it's basically going to be /srv/sales.
That's our endpoint to get all of the sales back and in fact we can do a quick test. So let's do
test and run the test and we can see we get our sales data back and we can auto detect our schema
based on what we got in this response. So if you now look at our schema we can see we've got ID,
region, country and amount. So we can now save that data resource. Now once we've done that we can go
ahead and actually think about using it. So we'll go back to my UI canvas and I'm going to go to the
marketplace to get the basic list. That's a really nice way we can show a list within SAP Build Apps. So
I'm going to install it and then I'm going to drag and drop it onto my page and then I'm going to
configure. So we're going to configure that. It's now recognized we've set up a direct integration
to REST API of sales. So I can select that one and then we'll need to configure our fields. What I can
do is put the region as the label and country as the title and then for the amount I'll have as
content what I'm going to do is just put in a little formula here. So basically I'm going to
use the string function. So I'm going to use the string function and then I'm going to do that on
the amount and then I'll do the same kind of thing for the ID. So what I'll need to do is find that
string function double click and then I can put in the ID. Hit submit. So now it's allowed us to
put all the things where we want them to be. I can go ahead and save and I can save from here
and now we're ready to test it. So let's go to the launch tab and let's preview it
and I'll open the web preview and it's going to be our sales app.
And indeed we're getting our sales data actually out. We're getting that shown in a list and that's
actually data that's coming from SAP HANA Cloud via our serverless function and crucially we've
got authentication and authorization behind that but you can see it's all working. It's actually
very straightforward and easy to do from SAP Build Apps. So in this video tutorial we've seen how we
can have a serverless function deployed to our SAP BTP, Kyma runtime in SAP Business Technology Platform
and then we can access that from SAP Build Apps as a REST service and it takes care of the
authentication and the authorizations etc. It's actually very straightforward to do. We didn't
have to write any code in how we actually use this serverless function from our SAP Build Apps
environment. You can find more video tutorials on our YouTube channel. If you'd like to be informed
as soon as new video tutorials are published then please subscribe. Thanks for watching.