WEBVTT

1
00:00.000 --> 00:00.090 align:middle line:84%


2
00:00.090 --> 00:02.520 align:middle line:90%
Now that we've set up the
basics of our Python script,

3
00:02.520 --> 00:04.573 align:middle line:84%
it's time to start doing things.

4
00:04.573 --> 00:06.240 align:middle line:90%
And the first thing
that a Python script

5
00:06.240 --> 00:09.967 align:middle line:90%
does with the REST API is
typically, get logged in.

6
00:09.967 --> 00:11.550 align:middle line:90%
Just like we said
when we were talking

7
00:11.550 --> 00:15.990 align:middle line:90%
about APIs in a previous
skill, we log in to a website.

8
00:15.990 --> 00:16.710 align:middle line:84%
Well, guess what?

9
00:16.710 --> 00:19.500 align:middle line:90%
Applications have to
log in as well when

10
00:19.500 --> 00:21.220 align:middle line:84%
it interacts with an API.

11
00:21.220 --> 00:23.700 align:middle line:90%
So what we have to do first,
the first block of code

12
00:23.700 --> 00:25.620 align:middle line:90%
that we're really going
to start interpreting,

13
00:25.620 --> 00:28.580 align:middle line:90%
is how do we get our
application, our Python script,

14
00:28.580 --> 00:31.080 align:middle line:90%
logged into FirePOWER
Management Center
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

14
00:28.580 --> 00:31.080 align:middle line:90%
logged into FirePOWER
Management Center

15
00:31.080 --> 00:33.300 align:middle line:90%
so that way any
subsequent requests

16
00:33.300 --> 00:36.570 align:middle line:90%
or subsequent blocks of
code can use that already

17
00:36.570 --> 00:37.860 align:middle line:84%
authenticated session.

18
00:37.860 --> 00:39.780 align:middle line:90%
That's what this
section is all about.

19
00:39.780 --> 00:41.140 align:middle line:84%
Let's get going.

20
00:41.140 --> 00:43.425 align:middle line:90%
So we did a great
job setting up what

21
00:43.425 --> 00:44.550 align:middle line:84%
we're supposed to be doing.

22
00:44.550 --> 00:47.210 align:middle line:90%
When we're building this
script, we imported some info,

23
00:47.210 --> 00:49.320 align:middle line:90%
we set up some
variables so that we

24
00:49.320 --> 00:51.720 align:middle line:90%
can reuse that stuff
later down the road

25
00:51.720 --> 00:53.310 align:middle line:84%
without having to type it all.

26
00:53.310 --> 00:56.970 align:middle line:90%
Now, it's time to perform
the first big action,

27
00:56.970 --> 01:00.210 align:middle line:90%
and that's getting logged in
to FirePOWER Management Center.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

27
00:56.970 --> 01:00.210 align:middle line:90%
and that's getting logged in
to FirePOWER Management Center.

28
01:00.210 --> 01:01.350 align:middle line:84%
Here's the big thing.

29
01:01.350 --> 01:03.572 align:middle line:90%
When you log into FirePOWER
Management Center,

30
01:03.572 --> 01:05.280 align:middle line:90%
you click that little
Submit button, what

31
01:05.280 --> 01:07.740 align:middle line:84%
really happens under the hood?

32
01:07.740 --> 01:12.120 align:middle line:90%
FirePOWER Management
Center send back a token,

33
01:12.120 --> 01:15.570 align:middle line:90%
and your web browser
holds that token.

34
01:15.570 --> 01:18.750 align:middle line:90%
That way anything you do
after the fact just re

35
01:18.750 --> 01:21.780 align:middle line:90%
sends that token it says, hey,
I'm already authenticated.

36
01:21.780 --> 01:24.610 align:middle line:90%
Well, our API works
the exact same way.

37
01:24.610 --> 01:27.420 align:middle line:90%
It's going to be sending off
your username and password

38
01:27.420 --> 01:31.270 align:middle line:84%
to FMC, and FMC returns a token.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

38
01:27.420 --> 01:31.270 align:middle line:84%
to FMC, and FMC returns a token.

39
01:31.270 --> 01:33.720 align:middle line:90%
So our code has to
be able to send off

40
01:33.720 --> 01:37.680 align:middle line:90%
that information first of
all, but then receive and hold

41
01:37.680 --> 01:38.820 align:middle line:84%
that token.

42
01:38.820 --> 01:41.610 align:middle line:90%
That way any requests we
do after the fact, we can

43
01:41.610 --> 01:43.680 align:middle line:84%
say, and look, here's my token.

44
01:43.680 --> 01:45.450 align:middle line:84%
I'm already authenticated.

45
01:45.450 --> 01:47.970 align:middle line:90%
That's what this batch of
code does, but beyond that,

46
01:47.970 --> 01:50.850 align:middle line:90%
this batch of code also
handles, what do we

47
01:50.850 --> 01:52.380 align:middle line:84%
do if it doesn't work right?

48
01:52.380 --> 01:53.800 align:middle line:84%
What if there is an error?

49
01:53.800 --> 01:56.400 align:middle line:90%
So there's a lot going on
during this login request

50
01:56.400 --> 01:58.320 align:middle line:90%
but you're going to
learn a lot about Python.

51
01:58.320 --> 01:59.560 align:middle line:84%
Let's jump into it.

52
01:59.560 --> 02:02.760 align:middle line:90%
So now, if I scroll down,
we're starting with lines 13,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

52
01:59.560 --> 02:02.760 align:middle line:90%
So now, if I scroll down,
we're starting with lines 13,

53
02:02.760 --> 02:04.500 align:middle line:90%
and you see
immediately, we've got

54
02:04.500 --> 02:06.660 align:middle line:84%
this thing that's called try.

55
02:06.660 --> 02:08.340 align:middle line:90%
That's literally
what it's doing.

56
02:08.340 --> 02:12.300 align:middle line:90%
It says, try to run
all of this code that's

57
02:12.300 --> 02:14.290 align:middle line:84%
indented right here.

58
02:14.290 --> 02:19.427 align:middle line:90%
And if there's any problem, if
there's an exception or error,

59
02:19.427 --> 02:21.510 align:middle line:90%
meaning maybe it's going
through this line of code

60
02:21.510 --> 02:23.220 align:middle line:90%
or this line of code
or this line of code

61
02:23.220 --> 02:25.050 align:middle line:90%
or this line of code,
anything that happens

62
02:25.050 --> 02:28.770 align:middle line:90%
in this indented that
doesn't work and it breaks,

63
02:28.770 --> 02:31.200 align:middle line:84%
jump down to the exception.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

63
02:28.770 --> 02:31.200 align:middle line:84%
jump down to the exception.

64
02:31.200 --> 02:35.370 align:middle line:90%
This, in Python, is
called a try-except block.

65
02:35.370 --> 02:40.290 align:middle line:90%
And in a lot of other languages,
it's called a try-catch block.

66
02:40.290 --> 02:42.330 align:middle line:90%
In fact, Python is the
only one that I've ever

67
02:42.330 --> 02:44.102 align:middle line:90%
seen that calls this
an except block.

68
02:44.102 --> 02:46.560 align:middle line:90%
Pretty much every other language
that I've ever worked with

69
02:46.560 --> 02:48.420 align:middle line:84%
calls it a try-catch block.

70
02:48.420 --> 02:52.290 align:middle line:90%
But the idea with Python is that
it's very specific about what

71
02:52.290 --> 02:53.970 align:middle line:84%
stuff gets indented.

72
02:53.970 --> 02:57.660 align:middle line:90%
It knows that when you say try,
followed by a little colon,

73
02:57.660 --> 03:00.960 align:middle line:90%
do everything under
the indentation.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

73
02:57.660 --> 03:00.960 align:middle line:90%
do everything under
the indentation.

74
03:00.960 --> 03:04.110 align:middle line:90%
And the except block says
that if there is a problem,

75
03:04.110 --> 03:07.820 align:middle line:90%
grab that exception,
and then here I've said,

76
03:07.820 --> 03:09.260 align:middle line:84%
print it out to the terminal.

77
03:09.260 --> 03:12.550 align:middle line:90%
Basically, when you run the
code, if there is a problem,

78
03:12.550 --> 03:14.490 align:middle line:90%
let us know what
that problem is.

79
03:14.490 --> 03:16.567 align:middle line:90%
Print out your little
error right there.

80
03:16.567 --> 03:18.900 align:middle line:90%
So now that we know that what
we're doing is we're first

81
03:18.900 --> 03:22.560 align:middle line:90%
going to try to run a block of
code, and if there's a problem,

82
03:22.560 --> 03:26.700 align:middle line:90%
print that error out-- they
also call this throwing an error

83
03:26.700 --> 03:28.800 align:middle line:84%
or raising an error--

84
03:28.800 --> 03:31.947 align:middle line:90%
we're now going to focus on what
is it that we're trying to do.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

84
03:28.800 --> 03:31.947 align:middle line:90%
we're now going to focus on what
is it that we're trying to do.

85
03:31.947 --> 03:33.780 align:middle line:90%
Actually, let me clear
the screen like this,

86
03:33.780 --> 03:36.480 align:middle line:90%
and I'm going to mark
this out right here,

87
03:36.480 --> 03:39.047 align:middle line:90%
and we're going to focus
on just this line of code.

88
03:39.047 --> 03:41.630 align:middle line:90%
I'm even going to clean off the
screen a little bit like this.

89
03:41.630 --> 03:45.240 align:middle line:90%
This is where your familiarity
with the HTTP protocol

90
03:45.240 --> 03:47.160 align:middle line:84%
really needs to shine.

91
03:47.160 --> 03:52.120 align:middle line:90%
You see, HTTP performs actions
that they call methods.

92
03:52.120 --> 03:55.320 align:middle line:90%
For instance, if you're just
trying to browse to a website

93
03:55.320 --> 03:58.500 align:middle line:90%
and retrieve data-- maybe
you're just trying to browse

94
03:58.500 --> 04:00.450 align:middle line:84%
a shopping website--
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

94
03:58.500 --> 04:00.450 align:middle line:84%
a shopping website--

95
04:00.450 --> 04:03.630 align:middle line:90%
you'll be doing what's
called a get request.

96
04:03.630 --> 04:06.780 align:middle line:90%
When you go to google.com
or cbtnuggets.com,

97
04:06.780 --> 04:08.820 align:middle line:90%
for the first time,
you're performing

98
04:08.820 --> 04:12.300 align:middle line:90%
a get request because you're
getting the HTML documents,

99
04:12.300 --> 04:14.130 align:middle line:90%
you're getting
the CSS documents,

100
04:14.130 --> 04:16.350 align:middle line:90%
you're getting the
JavaScript documents.

101
04:16.350 --> 04:19.704 align:middle line:90%
However, you may see a little
Search field right there.

102
04:19.704 --> 04:22.079 align:middle line:90%
There's a little text box,
and you can type whatever text

103
04:22.079 --> 04:23.700 align:middle line:84%
you want into that Search box.

104
04:23.700 --> 04:26.490 align:middle line:90%
Then you see a
big Submit button.

105
04:26.490 --> 04:30.090 align:middle line:90%
When you type into these Search
fields, you're creating data.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

105
04:26.490 --> 04:30.090 align:middle line:90%
When you type into these Search
fields, you're creating data.

106
04:30.090 --> 04:32.490 align:middle line:90%
You're creating new
information, and you're

107
04:32.490 --> 04:36.780 align:middle line:90%
telling it to perform some
action with that information.

108
04:36.780 --> 04:39.990 align:middle line:90%
When you provide
inputs into a website

109
04:39.990 --> 04:41.880 align:middle line:90%
and you tell it to
perform some action,

110
04:41.880 --> 04:44.130 align:middle line:84%
this is no longer a get request.

111
04:44.130 --> 04:47.230 align:middle line:84%
This is called a post request.

112
04:47.230 --> 04:49.710 align:middle line:90%
So if you think about it,
when you browse to a website

113
04:49.710 --> 04:53.010 align:middle line:90%
and you see a login
page that's got username

114
04:53.010 --> 04:55.350 align:middle line:90%
and a little field for you
to type in your username

115
04:55.350 --> 04:57.450 align:middle line:90%
and password and a
little field for you

116
04:57.450 --> 05:00.910 align:middle line:90%
to type in your password
and then a Go button,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

116
04:57.450 --> 05:00.910 align:middle line:90%
to type in your password
and then a Go button,

117
05:00.910 --> 05:01.987 align:middle line:84%
guess what you're doing?

118
05:01.987 --> 05:04.570 align:middle line:90%
When you type in your username,
when you type in your password

119
05:04.570 --> 05:06.310 align:middle line:90%
and you click that
Go button, you

120
05:06.310 --> 05:11.170 align:middle line:90%
are posting your log in
information into the website,

121
05:11.170 --> 05:13.330 align:middle line:90%
and that website is
supposed to do something

122
05:13.330 --> 05:14.380 align:middle line:84%
with this post request.

123
05:14.380 --> 05:16.900 align:middle line:90%
Typically, it validates
that you're the correct user

124
05:16.900 --> 05:19.900 align:middle line:90%
and returns to you some
sort of token or cookie

125
05:19.900 --> 05:21.770 align:middle line:84%
so that you can stay logged in.

126
05:21.770 --> 05:24.050 align:middle line:90%
That's exactly what
we're doing here.

127
05:24.050 --> 05:26.920 align:middle line:90%
And if you recall,
scrolling up just to here,

128
05:26.920 --> 05:29.830 align:middle line:90%
we imported the request
library so that we

129
05:29.830 --> 05:32.390 align:middle line:84%
could work with HTTP endpoints.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

129
05:29.830 --> 05:32.390 align:middle line:84%
could work with HTTP endpoints.

130
05:32.390 --> 05:34.720 align:middle line:90%
So now when I scroll
back down, you

131
05:34.720 --> 05:37.990 align:middle line:90%
can kind of see exactly
what we're doing right here.

132
05:37.990 --> 05:40.720 align:middle line:90%
With the request
library, we're going

133
05:40.720 --> 05:43.000 align:middle line:84%
to be performing a post request.

134
05:43.000 --> 05:47.080 align:middle line:90%
We're going to be sending
in our data to the URL

135
05:47.080 --> 05:50.770 align:middle line:90%
and the login your URL endpoint
that we specified above.

136
05:50.770 --> 05:52.720 align:middle line:84%
We're specifying authentication.

137
05:52.720 --> 05:54.400 align:middle line:90%
This is our username
and password

138
05:54.400 --> 05:56.030 align:middle line:90%
that we're storing
in a variable.

139
05:56.030 --> 05:58.300 align:middle line:90%
Now, this little thing
just verify equals false.

140
05:58.300 --> 06:00.940 align:middle line:90%
This is if you're using a
self-signed certificate.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

140
05:58.300 --> 06:00.940 align:middle line:90%
This is if you're using a
self-signed certificate.

141
06:00.940 --> 06:04.810 align:middle line:90%
This is saying, don't verify
the certificate on the website.

142
06:04.810 --> 06:07.600 align:middle line:90%
That FirePOWER Management
Center website sometimes

143
06:07.600 --> 06:09.940 align:middle line:90%
doesn't have a
valid certificate,

144
06:09.940 --> 06:11.680 align:middle line:90%
so by saying verify
equals false,

145
06:11.680 --> 06:14.848 align:middle line:90%
it's just going to ignore
the correct certificate.

146
06:14.848 --> 06:16.390 align:middle line:90%
But do you see what's
happening here?

147
06:16.390 --> 06:21.310 align:middle line:90%
We're using the post HTTP
method to send in data,

148
06:21.310 --> 06:22.960 align:middle line:84%
our username and password.

149
06:22.960 --> 06:24.790 align:middle line:90%
And we specify
the URL that we're

150
06:24.790 --> 06:26.630 align:middle line:84%
sending it into right here.

151
06:26.630 --> 06:29.830 align:middle line:90%
So we say request.post
then open parentheses.

152
06:29.830 --> 06:32.200 align:middle line:90%
The first thing that
comes is the URL.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

152
06:29.830 --> 06:32.200 align:middle line:90%
The first thing that
comes is the URL.

153
06:32.200 --> 06:34.570 align:middle line:90%
The second thing that
comes is authentication

154
06:34.570 --> 06:36.910 align:middle line:90%
that's specified by
username and password,

155
06:36.910 --> 06:38.560 align:middle line:90%
and then that's
really it if you don't

156
06:38.560 --> 06:40.600 align:middle line:84%
have a self-signed certificate.

157
06:40.600 --> 06:43.390 align:middle line:90%
This line of code,
this post does actually

158
06:43.390 --> 06:45.760 align:middle line:84%
perform the post request.

159
06:45.760 --> 06:48.460 align:middle line:90%
It actually sends
in that information

160
06:48.460 --> 06:50.920 align:middle line:90%
that we stored in
the variables above.

161
06:50.920 --> 06:53.890 align:middle line:90%
So pause right now in this
time and try and piece

162
06:53.890 --> 06:55.110 align:middle line:84%
all of these together.

163
06:55.110 --> 06:59.470 align:middle line:90%
See that this URL gets squeezed
in right here and the login

164
06:59.470 --> 07:02.140 align:middle line:90%
your URL gets
squeezed in right here
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

164
06:59.470 --> 07:02.140 align:middle line:90%
your URL gets
squeezed in right here

165
07:02.140 --> 07:05.810 align:middle line:90%
and the username and password
gets squeezed in right here.

166
07:05.810 --> 07:09.280 align:middle line:90%
And that's how it knows
where to send a post request

167
07:09.280 --> 07:12.880 align:middle line:90%
and what data it needs to send
into that post request too.

168
07:12.880 --> 07:15.310 align:middle line:90%
Now, that we've
uncommented this out,

169
07:15.310 --> 07:16.930 align:middle line:90%
take a look at what
we've got here.

170
07:16.930 --> 07:20.950 align:middle line:90%
We fire off our
post request to FMC,

171
07:20.950 --> 07:24.560 align:middle line:90%
and FMC is going to
send back a response.

172
07:24.560 --> 07:27.730 align:middle line:90%
So this block of code
performs the post action,

173
07:27.730 --> 07:29.830 align:middle line:84%
and it gets a response back.

174
07:29.830 --> 07:33.790 align:middle line:90%
That response is what we're
storing in this variable,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

174
07:29.830 --> 07:33.790 align:middle line:90%
That response is what we're
storing in this variable,

175
07:33.790 --> 07:36.620 align:middle line:90%
and that response contains
all sorts of data.

176
07:36.620 --> 07:39.650 align:middle line:90%
It includes a payload
of information,

177
07:39.650 --> 07:43.600 align:middle line:90%
but it also includes headers,
and in those headers,

178
07:43.600 --> 07:45.650 align:middle line:84%
it contains our token.

179
07:45.650 --> 07:48.460 align:middle line:90%
So in the next line of code
right here, what we're doing is

180
07:48.460 --> 07:51.640 align:middle line:90%
we're parsing out just
the headers that came back

181
07:51.640 --> 07:54.970 align:middle line:90%
from our response, and we're
holding just the headers

182
07:54.970 --> 07:56.380 align:middle line:84%
in this variable here.

183
07:56.380 --> 07:59.380 align:middle line:90%
That we can easily work with
just the info and the headers.

184
07:59.380 --> 08:01.840 align:middle line:90%
I don't have to worry about
any other information that
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

184
07:59.380 --> 08:01.840 align:middle line:90%
I don't have to worry about
any other information that

185
08:01.840 --> 08:05.320 align:middle line:90%
came back in the response,
like any text or the payload

186
08:05.320 --> 08:07.880 align:middle line:90%
or status codes or
anything like that.

187
08:07.880 --> 08:09.610 align:middle line:84%
So we've posted in the data.

188
08:09.610 --> 08:11.380 align:middle line:90%
We've now grabbed
just the headers

189
08:11.380 --> 08:12.940 align:middle line:84%
that came back in the response.

190
08:12.940 --> 08:16.570 align:middle line:90%
And from those headers, I can
grab the specific header that

191
08:16.570 --> 08:19.750 align:middle line:90%
we need, the
x-auth-access-token.

192
08:19.750 --> 08:24.320 align:middle line:90%
This is our token that we
need in subsequent requests.

193
08:24.320 --> 08:26.650 align:middle line:90%
Once we've gotten
just that token,

194
08:26.650 --> 08:29.650 align:middle line:90%
we store that token in
a variable called token.

195
08:29.650 --> 08:31.630 align:middle line:90%
And the last thing
we need to do is
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

195
08:29.650 --> 08:31.630 align:middle line:90%
And the last thing
we need to do is

196
08:31.630 --> 08:34.880 align:middle line:90%
we need to make sure that
we actually did get a token.

197
08:34.880 --> 08:38.080 align:middle line:90%
So we'll say, if
the token is empty--

198
08:38.080 --> 08:39.530 align:middle line:84%
that's what none means--

199
08:39.530 --> 08:41.110 align:middle line:90%
print out a little
message that says

200
08:41.110 --> 08:43.630 align:middle line:90%
we failed to get the
token, try again,

201
08:43.630 --> 08:45.580 align:middle line:84%
and then exit the script.

202
08:45.580 --> 08:47.650 align:middle line:90%
And then the very
last thing that we do

203
08:47.650 --> 08:51.010 align:middle line:90%
is we add our token
to our own headers

204
08:51.010 --> 08:54.250 align:middle line:90%
that we specified above when
we specified the content

205
08:54.250 --> 08:55.360 align:middle line:84%
type of JSON.

206
08:55.360 --> 08:57.130 align:middle line:90%
Now look, I know that's
a lot, but this is

207
08:57.130 --> 08:59.170 align:middle line:84%
what kind of goes in the APIs.

208
08:59.170 --> 09:01.330 align:middle line:90%
Moving into network
automation is
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

208
08:59.170 --> 09:01.330 align:middle line:90%
Moving into network
automation is

209
09:01.330 --> 09:04.120 align:middle line:90%
kind of like taking two
steps back so that you

210
09:04.120 --> 09:05.680 align:middle line:84%
can make a huge leap forward.

211
09:05.680 --> 09:09.620 align:middle line:90%
Not only do you have to learn
about how Python itself works,

212
09:09.620 --> 09:12.430 align:middle line:90%
but now you also have to
learn the nitty-gritty details

213
09:12.430 --> 09:14.210 align:middle line:84%
about the HTTP protocol.

214
09:14.210 --> 09:17.560 align:middle line:90%
This is why I say, again,
feel free to pause.

215
09:17.560 --> 09:20.025 align:middle line:90%
Go back, watch this
content over and over again

216
09:20.025 --> 09:22.150 align:middle line:90%
if that's what it takes
because when I was learning

217
09:22.150 --> 09:24.460 align:middle line:90%
this stuff not
too long ago, this

218
09:24.460 --> 09:27.587 align:middle line:90%
was stuff that took me a
week or more to finally grasp

219
09:27.587 --> 09:28.420 align:middle line:84%
and get the hang of.

220
09:28.420 --> 09:31.240 align:middle line:90%
This is OK to repeat
over and over again.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

220
09:28.420 --> 09:31.240 align:middle line:90%
This is OK to repeat
over and over again.

221
09:31.240 --> 09:34.870 align:middle line:90%
But let's repeat what we've done
so far in this particular code.

222
09:34.870 --> 09:37.420 align:middle line:90%
We're looking at a
try and except block.

223
09:37.420 --> 09:39.010 align:middle line:90%
That way we're making
sure that we're

224
09:39.010 --> 09:41.200 align:middle line:90%
trying to perform
these login requests.

225
09:41.200 --> 09:45.170 align:middle line:90%
We're trying to perform the
post request to grab the header.

226
09:45.170 --> 09:47.990 align:middle line:90%
And if anything goes wrong,
we can just back out of it

227
09:47.990 --> 09:49.870 align:middle line:90%
and say, this
error occurred when

228
09:49.870 --> 09:51.430 align:middle line:84%
we were trying to post it in.

229
09:51.430 --> 09:53.760 align:middle line:90%
Here, on this particular
block of code,

230
09:53.760 --> 09:58.510 align:middle line:90%
we post in to this URL what
our username and password are.

231
09:58.510 --> 10:02.380 align:middle line:90%
And then we store the tire
a response in a variable
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

231
09:58.510 --> 10:02.380 align:middle line:90%
And then we store the tire
a response in a variable

232
10:02.380 --> 10:04.030 align:middle line:84%
called login response.

233
10:04.030 --> 10:06.940 align:middle line:90%
That response contains
lots of stuff.

234
10:06.940 --> 10:08.680 align:middle line:84%
It contains a payload of data.

235
10:08.680 --> 10:10.450 align:middle line:84%
It contains a status code.

236
10:10.450 --> 10:12.610 align:middle line:90%
It contains headers,
and those headers

237
10:12.610 --> 10:14.480 align:middle line:84%
are what we really care about.

238
10:14.480 --> 10:18.280 align:middle line:90%
So in the next line, we say,
from the login response,

239
10:18.280 --> 10:21.775 align:middle line:90%
everything that came back,
grab just the headers.

240
10:21.775 --> 10:23.870 align:middle line:84%
I only care about the headers.

241
10:23.870 --> 10:27.070 align:middle line:90%
So we store those headers
in a variable called

242
10:27.070 --> 10:28.780 align:middle line:84%
just-the-response-headers.

243
10:28.780 --> 10:31.345 align:middle line:90%
Once we have
just-the-response-headers,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

243
10:28.780 --> 10:31.345 align:middle line:90%
Once we have
just-the-response-headers,

244
10:31.345 --> 10:35.110 align:middle line:90%
I can say, get me this
particular header.

245
10:35.110 --> 10:36.910 align:middle line:84%
I only want this one header.

246
10:36.910 --> 10:39.160 align:middle line:84%
That's the x-auth-access-token.

247
10:39.160 --> 10:41.680 align:middle line:90%
That's the token
that was returned

248
10:41.680 --> 10:44.200 align:middle line:84%
upon a successful login request.

249
10:44.200 --> 10:46.810 align:middle line:90%
And I stored that token
in a variable by itself.

250
10:46.810 --> 10:49.430 align:middle line:90%
You see how we kind of
whittling it down a little bit?

251
10:49.430 --> 10:52.630 align:middle line:90%
We've got this huge response
that we store in a variable.

252
10:52.630 --> 10:54.370 align:middle line:90%
Then we grab just
the headers, and we

253
10:54.370 --> 10:55.720 align:middle line:84%
store that in a variable.

254
10:55.720 --> 11:00.280 align:middle line:90%
Then we grab just one header,
the x-auth-access-token that we
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

254
10:55.720 --> 11:00.280 align:middle line:90%
Then we grab just one header,
the x-auth-access-token that we

255
11:00.280 --> 11:02.440 align:middle line:90%
store in a variable
called token.

256
11:02.440 --> 11:05.290 align:middle line:90%
We validate that that
token isn't empty.

257
11:05.290 --> 11:06.085 align:middle line:84%
It can't be none.

258
11:06.085 --> 11:07.870 align:middle line:84%
It has to add some info.

259
11:07.870 --> 11:11.110 align:middle line:90%
And lastly, we add that
token to the headers

260
11:11.110 --> 11:12.610 align:middle line:84%
that we created above.

261
11:12.610 --> 11:15.230 align:middle line:90%
That way in our next
request, we can just say,

262
11:15.230 --> 11:18.730 align:middle line:90%
hey, use those headers that
specify what my token is.

263
11:18.730 --> 11:21.460 align:middle line:90%
We don't have to worry about
copying and pasting tokens

264
11:21.460 --> 11:22.360 align:middle line:84%
over and over again.

265
11:22.360 --> 11:24.310 align:middle line:90%
We just stored the
token in a variable

266
11:24.310 --> 11:25.878 align:middle line:90%
and then tacked it
onto our headers

267
11:25.878 --> 11:27.670 align:middle line:90%
that we're going to
use in the next Nugget.

268
11:27.670 --> 11:30.170 align:middle line:90%
So that's getting
logged into a REST API.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

268
11:27.670 --> 11:30.170 align:middle line:90%
So that's getting
logged into a REST API.

269
11:30.170 --> 11:32.260 align:middle line:90%
Honestly, this is one
of the hardest parts

270
11:32.260 --> 11:34.960 align:middle line:90%
about working with an
API in any platform

271
11:34.960 --> 11:36.730 align:middle line:84%
is just getting authenticated.

272
11:36.730 --> 11:39.130 align:middle line:90%
But that's how you get
authenticated to FirePOWER

273
11:39.130 --> 11:41.052 align:middle line:90%
Management Center
Security Appliance.

274
11:41.052 --> 11:42.760 align:middle line:90%
I hope this has been
informative for you,

275
11:42.760 --> 11:45.060 align:middle line:90%
and I'd like to thank
you for viewing.
