Welcome to the SAP HANA Academy. My name is Bob, and in this video series from the SAP HANA Academy
and Digital Partner Engineering, we'll be looking at SAP Fieldglass integration.
In this video, we're going to be looking at API authentication
using tokens, within Postman, when connecting to SAP Fieldglass. In the previous few videos we
looked at using integration tools to enable a specific integration connector. The integration
connector that we've enabled is to do with creating the job postings within SAP Fieldglass.
So to show you what it's like, I'll filter on all my list of available connectors.
If we apply that filter, you can see that we've got one called jobposting_upload.
It's an upload connector which essentially means we'll be writing data to SAP Fieldglass
and in terms of knowing the configuration operations for this connector,
we looked at using the SAP Fieldglass connector library. We looked at the in-depth documentation
specifically for that connector. You have overviews, file formatting (which tells you
about all the required columns needed for that connector), It also details all the components like
whether the columns are required, and gives you various notes on using that specific connector.
Now that we've prepared the connector, we can move onwards to Postman. Now if you haven't
used it before, Postman is an API development tool which helps you build, test and modify APIs.
You can perform various types of http requests such as GETs and we'll be performing POSTs .
We'll also be looking at using environments. If you look in the description field for
this video you'll see a link to the resources that i'm going to be using in this part of the
video, so we're not going to build anything from scratch. Instead, we're going to import some files
which will set everything up for us. This will give you a good sample of how things work.
At the moment, we have no environments or no environment variables
but we can import these from some files i've got available on my laptop. ( the link will
be in the description). In case you haven't done this before you'll go to Environments tab
and you'll go to Import and if i upload the file and i select that environment.json file,
we can see we've got an environment variable called digital asset buyer.
Alongside the environment variables ,we'll need to import the code. We do this within a collection.
So wiithin the collections, i'll select upload files. We'll select that collection
and i'll select import. Here you can see we've got a collection which contains two pieces of code:
you've got a GET access piece of code and an Upload JP (which stands for job posting).
What we'll need to do firstly is select our environment variable and just to give
you an overview these are some of the variables that we're going to be using...
URL is simply the name of your SAP Fieldglass tenant, you've got the API key (which you
know you can get from your integration tools within view api application key). In terms of basic
authentication and access token, that's what we're going to look at how to create in this video.
Before we can actually create a job posting, which is that upload jp, we need to deal with
authentication by getting the access token. Now Fieldglass supports oAuth2 authentication to make
any API calls, and so we need to prepare authorization to get an oAuth2 token. This allows
you to approve one application interacting with another on your behalf without giving away your
password. So we need to get hold of this token. Now our URL will have two parameters: a grant typ,e
which is the way the application gets the access token; and the response type, which is
actually what is returned. So we're requesting client credentials and will receive back a token.
Of course, the orange piece within the POST URL indicates the tenant that we're connecting
to, the SAP Fieldglass tenant, so that will of course come to us from our environment variables,
and after we've specified the token url we're including as two parameters in our post.
Now in terms of the header, we need the content type to be returned as json .
We need to specify a key which is x-ApplicationKey which is that api key again.
We get that from one of our environment variables. Lastly we'll need another key authorization
which has the value "Basic" with a capital B space and then again we're going to get that
basic authentication from our environment variable. If we go to the body tab there's nothing needed
in the body tab, and so the question is how do i get the values of the environment variables?
Well again if we go to our headers, we know where we can get that API key. We specified it in
our environment variable, but where did this come from? Well if i go back to my integration tools,
we can get this from our API Application kKey list. So if i go to View API Application Key,
we can select the specific application that i'm using in this video series -- which is job posting.
Here i can copy that application key. So this is that key that is placed within API key within
Postman. That api application key is associated with the client secret and of course the client id.
That's the first step. The second step is to deal with that authorization.
To do that, we need to do some translation using Base64. There are many
ways you can do this. If i do a search for "Base64 guru" and i go to that Base64 guru ,
what we need to do is convert some text to Base64.
If i select it and grab these name (which is "apiuser_ gmcp" then I'll paste it here as text.
We'll then place a colon, and after it we'll paste in that license.
So i'll grab the license, copy it and paste it here ad text
Next, we'll encode that text to Base64 and we'll grab that result which will then
be placed into the environment variable. If i go back to my list of environment variables , this
is what is placed in that basic authentication environment variable. Now you'll also see we've
got another environment variable called "access token." Now we don't actually need it for this post,.
this GET access token post, but what it's used for is once i've got the access token i'll write
the value of it as an environment variable. That piece of code is done here within my tests tab.
Here we can see some code which takes the response that we get from the post and from the response
body it sets an environment variable called "access token" from the access_token response.
There's nothing else to configure. We've actually configured everything. There's nothing
needed to be added to our list of headers so all i need to do is go ahead and send this post.
And here we can see the access token as a response.
Again it's automatically been added as an environment variable within this session .
We can see the token type is of Bearer and it expires in 7200 seconds, which is in two hours.
So now that we've generated that access token and written it back in our session as an environment
variable, in the next video we'll look at creating a job posting again using Postman