So let's now look at how we can use the REST API for Cisco's SD1.
Now I will say there are some similarities to the SD1 REST API with what we saw
in DNA
center.
We're going to have to deal with authentication, so we'll be dealing with
passing in our username
and password credentials.
But there are some subtle differences.
So with that said, let's dive in and see a dimension.
So if you happen to search for Cisco's SD1 REST API documentation, let's click
this link
here.
Then as we can see, then the left hand side, we have our options. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Then as we can see, then the left hand side, we have our options.
If I go to authentication right here, we can see here straight away, we're
going to have
to log in with a username and a password.
But here is something quite unique.
We're going to have to specify the username and the password and submit them in
this particular
form.
J_Username and J_Password.
This is essentially with reference to Java.
Java username, Java password.
And essentially, that will give us a token with which we can use to authent
icate going WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
icate going
forward.
But this is going to come in the form of an HTTP cookie, the J session ID or
the Java session
ID.
Next point, which is very, very important.
Remember with respect to DNA center, we had to specify a particular header.
And that header was our XAuth token.
In the case with Cisco's SD1, we do not specify this.
We instead use a content type header, but the value we provide is going to be
application
forward slash X www form URL encoded. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
forward slash X www form URL encoded.
So this here is a big distinction between the operation of these two different
APIs.
So let's begin getting hands on.
And then what I will first do is go to the DevNet sandbox.
And in this case here, I'm going to look for SD1.
If I set it for SD, we can actually see I have the always on sandbox.
Let's click this here.
And again, if we go to the access details, we can see this is the URL.
If I just copy this here, paste you in, I'll just go to advanced and I will WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If I just copy this here, paste you in, I'll just go to advanced and I will
click this
link here.
And now I can log in with the username, which again is DevNet user.
And we also have this password here.
So let's copy this to DevNet user.
And then the password, let's log in.
All right.
So we log in.
We'll go to the end of the course.
And then we'll go to the end of the course.
WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And then we'll go to the end of the course.
WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And then we'll go to the end of the course.
And then what we'll do here is we'll choose x, w, w form, u, r, l encoded.
And the key here, and this is why we're doing it this way, is we're actually WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And the key here, and this is why we're doing it this way, is we're actually
going to specify
j_user_name, remember, j have a username, j have a password.
And the corresponding value will be definite user.
And again, we're going to have j_password.
And again, let's just grab that password value.
This is one right here.
And just paste this in.
So now we have the actual end point to get the token.
We'll specify the post request.
We have our headers specifying.
We're going to be sending application x, w, w form, u, r, l encoded data. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
We're going to be sending application x, w, w form, u, r, l encoded data.
And in the body, we have the j_user_name and j password for authentication.
If we send this off right here, we get the response of 200.
This indicates a good sign.
However, we don't actually see anything in the output unless we go to the
headers right here.
And if we scroll up a little bit, we're actually going to see this option right
here, the set
cookie, see this?
And the actual value here is the j session ID.
See from this point here of the equal sign, all the way to the first semicolon. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
See from this point here of the equal sign, all the way to the first semicolon.
This here, this is the actual cookie that I want to be storing.
Now the way Postman is going to handle this is that it's actually going to save
this session here.
So in fact, if I go and choose to go to my collections, choose new, and the new
HTTP request,
if I go to cookies, you're going to notice that we actually do have the session
, the j session
ID should I say stored right here.
All right, so now we have this j session ID cookie.
With us now available to us and stored within Postman, what we want to do is to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
With us now available to us and stored within Postman, what we want to do is to
use this
to get our CSRF token.
This is basically a token to prevent something known as cross-side request for
geries, which
is once again just a simple security measure to prevent particular attacks.
So as per the documentation as we saw, we just sent a request to j security
check, the port request
that is, and that has returned this j session ID cookie.
This has allowed us to authenticate, and now we're going to have to get this CS
RF prevention token.
Now it says the other way we do this is we target this particular URL, this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now it says the other way we do this is we target this particular URL, this
time with a get request,
and we're going to have to pass in the j session ID cookie.
So let's go and do this then.
Let's grab the actual endpoints, we're going to target.
Let's paste this in, and again let's get the devnet sandbox appended in.
Remember this time it's going to be a get request.
The j session ID is stored already within the cookies automatically with Post
man, so we don't
have to do that configuration manually.
We're going to specify the content type, it's going to be application JSON.
Let's go to the headers, we'll say content type as application JSON. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Let's go to the headers, we'll say content type as application JSON.
So now we have a new endpoint utilizing the get method with the cookie
configured as a
it's now available, and we have our headers of content type application JSON.
If we now send this off, we once again get a 200 status code, and this time we
're actually
getting the CSRF token right here or the CSRF prevention token.
So this is the one we want to be using to actually make all further requests to
the API.
So again if we go back to the documentation, if we go to the API reference WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So again if we go back to the documentation, if we go to the API reference
right here,
so we can see straight away the servers are forward slash data service, and
then if we
scroll on down we can see all of these additional options we can use.
If you want to get particular admin information, here are the endpoints we can
use, scrolling
on down, we can get alarm details for monitoring, and we have a ton more
available options as
you can see right here.
So say for example this option here, device, this will list all devices within
SD1.
So what is the path going to be?
Well it's going to be as we saw at the very top. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Well it's going to be as we saw at the very top.
So if we go back, remember we have our token now, let's create a new request,
let's pass
in this URL of data service and device, it will be a get request we're sending,
and within
the headers we're going to say x, xsRF, hyphen token, and then I'll paste in
the value of
that token I just got, remembering in the cookies we still have our j session
ID stored
right here.
So if I now send this get request to this end point, specify my headers with WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I now send this get request to this end point, specify my headers with
the token
that we have now got, if I hit send here, give it a moment, what we're actually
seeing
here is once again a 200 status code and we're now getting a list of all
devices within
SD1.
So that's right here, all this information.
Now no doubt if this is the first time working with the SD1 API, this can be a
little bit confusing.
As a recap, the first time we're going to have to do is to login via our
username and
our password, the way we do this is by specifying our j username and our j
password, the information WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
password, the information
is going to be sent x www.form URL encoded, and once we send this off, this is
going to
give us our j session ID, which is pretty much our little cookie, we then use
this particular
cookie to get our CSRF token, and then we use this token going forward to make
all of
our requests to the available end points within SD1.