Hi and welcome to this section where
we're gonna talk about building quality
APIs. In this video we're going to talk
about debugging your API. So creating API
test is an important skill, what do you
do when a test fails? Being able to debug
failures and figure out what to do is an
important aspect of API testing. So let's
take a look at a failing test and see if
we can figure out what's going on. I have
here tests that I've set up to fail, so
when we click on it,
send, can see the test results here have
failed. It's saying that we expect
undefined to deeply equal Europe /
London. So what's going on here? What does
this even mean? Well if we look at our
test, so if we look at the actual assert
that we're using up here, we can see that
it's expecting the JSON data and the
timezone key in that data to have a
value of Europe slash London, but what
this is saying down here is that this
Europe London part that makes sense
that's what we're looking for, but it's
saying that Vout the key here the
timezone is undefined. What that probably
means is something has gone wrong with
our response, we're not getting back the
response that we expect. And if we look
at the body we can see that is indeed
the case. We would expect to have some
kind of JSON here with information about
the London timezone, but instead we seem
to have some long list of locations,
maybe locations as API takes I don't
know, but it's some long list of
locations. That seems really odd, so let's
see if we can find out a little bit more
about what actually got sent to the
server. So let's click here on the
console to open up the Postman console,
and then let's send our request again.
And if we look at the console you can
see that we have some information here
about what got sent to the server. So we
can see the headers that were sent along
with the API location that we sent, and
then we can see a little more detail
about what came back. Now everything
seems to be fine here, so let's look at
something else. Let's close that and
let's try something here, let's just
change this to Bob, so we'll change it to
something that doesn't make any sense
and send this request, and see what
happens. Now interestingly we get this
same error, and if we look at the body we
got the same response back. So it seems
like it doesn't care what we're putting
in here. So there must be something else
going on, it seems like it's not a
problem that's happening here at the end
of the URL. But maybe let's go look at
the documentation and see what it says.
So we look here in the documentation, we
can see that we should have world time
API org, look at that we have world time
API that org that looks good, and then we
have slash API slash time zone followed
by the area and location. So here we have
slash API slash time zones, okay so we
have an extra s in there. So let's remove
that and send this request, and see what
happens. Now we got something back, error
unknown location. Okay so this is a very
different thing that we were seeing
before. It still gives us this undefined
because the test here, there's no time
zone key in this response,, but we're
getting an unknown location so we're
getting somewhere we're getting a
different error message. In this case if
remember we changed this to say Bob, so
let's change that back to London so that
it's a valid location, and send that. And
now you can see we've gotten back a
response that has data about the London
time zone, and if we look at the test
results here everything has passed and
is as we expected. So when debugging
tests you can see there's a number of
things that we can do. Wwe can experiment
with different things in the response to
try and help us understand what's going
on,
we can look at the actual data being
sent to the server to dig in and get
more details in the console, and of
course another important source of
information is the documentation. By
digging through these sources of
information, and by trying and
experimenting with things we can figure
out what's going wrong in our test. In
the next video we're going to look at
how we can improve our API documentation,
so that we can keep things well
documented with Postman.