So friends let's go and check out the REST API for Cisco DNA Center otherwise
known as
Catalyst Center. So as you may know as I like to do for exploring a REST API
particularly for
the very first time is just go straight to the documentation it's the best
place to find that
information. So if you happen to search for Cisco DNA Center REST API
documentation let's go down to
this link right here for the quick start and as we can see here this
documentation gives you
pretty much all you need to explore Cisco's DNA Center we have the general WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
pretty much all you need to explore Cisco's DNA Center we have the general
overview of the
actual platform right here. You have examples so on so forth but the very first
thing that I
really want to focus in on is this concept right here of authentication. Really
try to remember
this when it comes to Cisco DNA Center's API we are going to be using a token
based authentication
pretty much what that means is that before we do anything we're going to have
to get this token
and once we have it we will use it in all the follow-up requests. So an example WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and once we have it we will use it in all the follow-up requests. So an example
below what we
actually have here is a Python script but in our case we're going to be doing
this just simply
utilizing Postman but there is some good information that we have right here.
First thing I want you
to notice this endpoint right here this is the endpoint we use when we want to
get our token. Now
when I say get or token this is the next thing that I want to highlight to you
because intuitively
when you want to get something and you're thinking of raised APIs you might
well assume that we're
going to be sending a get request in this case here this is not what we're WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
going to be sending a get request in this case here this is not what we're
going to do when we want
to get a token we actually want to send a post request and I know it's kind of
confusing not
really the most intuitive thing but really really important to remember the
post request is how we
actually get that token and once we've got it well then they can really begin
exploring the API.
Now another point to note that we can see from this information is that the way
we actually get
this token it's not just a post request we send to this particular endpoint we WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this token it's not just a post request we send to this particular endpoint we
also have to supply
two vital pieces of information we're going to have HTTP basic authentication
and that includes a
username and password from that point we should effectively return a token key
and inside that
key will actually get the token that we can then use. Okay so again if we just
scroll on down we're
going to see information relating to the error codes the responses so on so
forth if you so wish
read this in your own time what I want to do now though as I want to use my WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
read this in your own time what I want to do now though as I want to use my
favorite tool to explore
a raised API and that is postman we've seen this till before in earlier skills
so let's just go
and pull that up then so over on postman all I will do is choose new and I will
create a HTTP
request okay okay so the very first thing that we're going to have to do here
is we are going to
have to find an endpoint that we can actually target there's no point just
sending these requests
if we are not talking to Cisco DNA sensor now the best place to test out Cisco WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
if we are not talking to Cisco DNA sensor now the best place to test out Cisco
products if you
don't actually have them on site and available to you is to go to the devnet
sandbox so this
is exactly what I'm going to do so once again let's go and pull up another
window within our browser
so let's search for Cisco devnet sandbox click on this right here and let me
just zoom it a
little bit so you can see it all you have to do is to log in and then choose to
launch the sandbox
now remember Cisco DNA center is now revamped and renamed as catalyst center so
let's just search
for center this is the one that I want to use the always on sandbox doesn't WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
for center this is the one that I want to use the always on sandbox doesn't
require any type of
reservation so if I just click this here okay I'm just zoom out a little touch
if we go to the
access details here we can see this is how we actually access the sandbox in
fact we can just
test it out very briefly let's just copy this URL open up a new tab paste it in
and what I'm going to
do is I'm going to supply the information that I need to log in that's going to
be the username
and the password now if you can see here the username is devnet user so let's
just paste this in and
for the password it's simply as we can see right here Cisco 123 exclamation WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
for the password it's simply as we can see right here Cisco 123 exclamation
marks let's just copy
this and paste your in let's log in and now we have access so obviously this is
available to us the
credentials are correct we don't want to log in though directly via the UI we
want to be going
and authenticating with postman to send these API requests so let's use that
same information
this time in postman so let's go back to our application right here what I'm
going to do is
I'm going to paste in the URL again just grab your right here copy and in order WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
I'm going to paste in the URL again just grab your right here copy and in order
to authenticate
we're going to have to use a very particular endpoints remember from the
documentation let me just
pull us over a little touch scrolling on up let's go back to authentication
look at the example
this particular end point here is the one we want to append so let's copy this
we go back here
and just do forward slash paste that send a file that's an extra forward slash
let's get rid of that
and remember very important we don't want to send a get request we want to send WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and remember very important we don't want to send a get request we want to send
a post request so
let's make sure that's the case now also we're going to have to specify what
our authorization is
going to be we're going to use basic authentication so I will say DevNet user
is going to be the login
and the password will be Cisco 123 exclamation mark so if that's now done we
have the post request
we have the actual always on sandbox we're targeting the correct end point to
get the token in
of supplied the correct username and password with this now done we should be
able to send off the
request and get the response so let's just click send here all right so we WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
request and get the response so let's just click send here all right so we
actually get this token
key back and more importantly we actually get the value of the token so let's
just copy it this okay
and from this point on we are going to use this value to make any subsequent
request to Cisco
DNA Center the actual request that you want to get information about the
devices under the
management of DNA Center so check this out all we'll do is create a new HTTP
request once again
no we do know we're going to be targeting the always on sandbox such as paste WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
no we do know we're going to be targeting the always on sandbox such as paste
this in as a base value
for the authorization though this time we're actually going to get that by
passing in values
via our headers so here's what i'm going to do the key here and this is
actually very important to
remember if we happen to scroll further down looking at the python example
right here what we're
actually doing is presenting a get request to get information about IP
addresses of a particular
network device okay now within the headers we have two headers we have a
content type header
specifying we want JSON but this is the part that i really want to highlight in WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
specifying we want JSON but this is the part that i really want to highlight in
all of our requests
we want to be supplying within the headers this particular key right here x off
token and then
the corresponding value will be the token that we just got in that previous
request and from this
point on this is how we're going to be allowed to get the information about
this particular endpoints
so let's go and just fill that information in right now the content type and
the x off token
so within the headers we'll just say x off token and the corresponding value WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
so within the headers we'll just say x off token and the corresponding value
all i will do is i'll
paste in the token that i just got in the previous request so let's go here
paste in this value
there we go okay so we should have the information needed to make the request
but what are the
available endpoints once again we can find this directly from the documentation
so if we just
scroll on down we can see these other options in the left hand side so you want
to get information
about devices let's click this right here notice we have this option for end WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
about devices let's click this right here notice we have this option for end
points and methods
used let's click this right here and see some examples so we've already seen
this one right here
we send a poster quest to get the authorization token we stole that token and
then use it for
these types of requests right here okay if we want to get information about
network devices
just generally we could grab this endpoints and remember now it's going to be a
get request
not a post request so let's paste in this new value make sure we're going to
use a get request
this time we have the x off token and with that now done if i just click send WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this time we have the x off token and with that now done if i just click send
here we send off
the request and now we actually get back a 200 status code okay so if we just
go and inspect the
response what we're actually seeing here are a whole bunch of different devices
under the
management of DNA center here is the first one right here the switch we can see
it's MAC address
right here and things like the software version the serial number of that
device it's uptime so
on so forth and if i just scroll on down we're going to eventually see we have
another device WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
another device
under our control and this has a different MAC address with a different serial
number so on
so forth and again scrolling on down more and more devices under the management
of Cisco DNA
center and again if i want to get other information like go back to the
documentation let's maybe
say i want to i don't know let's go with health monitoring okay what can i do
choose endpoints
and methods use we can see we can send a get request to get network health let
's grab this
right here as we know as per the request the headers still have the x off token WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
right here as we know as per the request the headers still have the x off token
with this value
all i will do now is send a get request change the end point paste this in and
if i click send
we send off the request we get the 200's data's code back and now this time we
're getting different
information related to the net work health and as we can see here we have a
health score of 100
so really as a recap when we're going to be interacting with the DNA center
rest API we're
going to have to first send a post request to gather a token for our
authentication once we have
this token we're going to pass it in to future requests with our headers and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this token we're going to pass it in to future requests with our headers and
the header is going
to have this x off token key and then we pass in that particular value from
this point on this is
how we're going to make all of our requests this will be our validation so to
speak and then all
we do specify the end point that we want to target for the particular
information that we want
and then use the correct HTTP method whether it's a get request or post request
we can find that
information directly from a documentation by choosing the information that we WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
information directly from a documentation by choosing the information that we
want go to say for example
path trace look at the end points and method used in the case here we have a
post request correlating
to this end point if you want to get flow analysis we can send a post request
to make a change to
our flow analysis right here if you want to delete information well we can
target this particular end
point this time with a delete request so on so forth but like i say the crucial
point is that token
is baked in to all of these requests.