Provide Authorization Credentials
Learning Objectives
After completing this unit, you’ll be able to:
- Configure authorization details.
- Use an Authorization helper.
Securely Access APIs
APIs may require authorization to ensure that client requests access data securely. This can involve authenticating the sender of a request and verifying that they have permission to access relevant data. The authorization model is specified by the API provider.
Configure Auth Details
You can pass auth details along with any request you send from Postman. Auth data can be included in a request header, body, or as parameters to a request.
The NASA Astronomy Picture of the Day API requires an API key be included with each request as a query parameter. Let’s see this in action.
- Select Picture of the Day.
- Deselect the
api_key
query parameter.
-
Save your update.
- Then click Send. You see an error response.
Go ahead and deselect the api_key
query parameter in Pictures from November 2023 as well.
Make sure you Save your update.
Let’s learn a new way to handle authorization in Postman.
Use Authorization Helpers
Under the Authorization tab of the request builder, you can enter and configure your auth details for Postman to automatically populate the relevant parts of the request. You can use an authorization helper for a request, folder, or collection.
Since all of the requests in the Trailhead module collection require the same authorization type, let’s add an authorization helper to the collection.
- Select Trailhead module.
- Click the Authorization tab.
- Select API Key from the Type dropdown.
- Fill in the key value pairs.
- Key:
api_key
- Value:
{{nasa_api_key}}
- Select Query Params from the Add to dropdown.
-
Save your changes.
- Click into any request you have saved. You see that Postman automatically adds the proper credentials under the Params tab.
Remember to use variables and collections to define authorization details more safely and efficiently, letting you reuse the same information in multiple places. If you group your requests in collections and folders, you can specify auth details to reuse throughout a group.
In the next unit, let’s learn some ways to debug and troubleshoot when things aren’t going as expected.