Debug and Troubleshoot Unexpected Behavior
Learning Objectives
After completing this unit, you’ll be able to:
- Reference console logs.
- Read error messages.
Debug Unexpected Behavior
When an API is not behaving as you expect, use the Postman console to help with debugging.
Open the console from the icon on the bottom left of Postman. Postman logs every request in both raw and pretty form. You can inspect headers, certificates, requests, and responses from these network calls. Let’s see it in action.
Send the second request in your collection and inspect the console output.
- Open Pictures from November 2023.
- Click Send.
- Then click at the bottom left of Postman.
- Expand your latest request to explore the log.
- Click Clear to clear the console before running the next request.
Insert Console Statements
Using log statements at appropriate locations in your scripts helps identify the source of any issues. You can verify code is executing in the right order and inspect the values of variables at a certain moment in time.
- With Pictures from November 2023 still open, insert the following code on the first line of the Tests tab,
console.log(`From the Tests tab, number of pictures is: ${pm.response.json().length}`)
- Send the request and inspect the console output. You’ll see the statement response.
Continue Your Journey with Postman
You’ve gone through a lot in this module, from setting up your Postman workspace to testing, using variables, and debugging. Congratulations!
To continue your journey with Postman, here are some additional resources to check out.
-
Postman Learning Center: In addition to the docs, there are helpful guides and other support resources to level up your API skills.
-
Postman Community Forum: Postman has a large and active community, and someone might be willing to help if you ask nicely.