In this lesson, you'll learn how to add custom headers to an API request in Postman. We'll walk through finding automatically applied headers that are added to requests by default and how you can configure your own headers for custom requests.
Colby Fayock: [0:00] We're going to start off with a new request in Postman, where we're posting to an endpoint called post, the data test equals true. We can see this working, and if we hit Send, we can see that the status is 200, which is OK.
[0:10] Because on the code we're console.logging out parts of the event including the Path, HTTP Method, Body, and Headers, we can see in the terminal that we can see the Path as /post, the Method as POST, the Body of test equals true, and we also see all the default Headers that are set in Postman.
[0:25] If we wanted to modify the headers or simply see what's being sent, we can click the Headers tab inside of Postman. Currently, we don't see any headers there, but if we click hidden, we can see all the ones that are automatically generated and included with Postman.
[0:36] Because we're setting our body with the type of JSON, it automatically includes Content-Type of application/json, and because we're sending this from Postman, it also includes a User-Agent of PostmanRuntime.
[0:46] If we wanted to add our own custom headers, we can use this Headers table and add a Key-Value pair, so if I wanted to add a key of test and a value of true, I can now send my request, and I can now see that inside of my Event Headers, I have test equals true.
[0:59] When we add authorization through the Authorization tab, we can see that it's added as a hidden header, but if we wanted to do that manually, we can turn that off or we can add the authorization header and then set our value which we can then post and see that it gets sent with our request.
[1:12] In review, we had a POST Request where we wanted to send custom headers. We were able to see all the headers that were hidden that are generated by Postman itself. We can also see that we can set our own custom headers using the Headers table.
[1:22] When we send our request with those custom headers, we can see right in the event logs our custom header.