Reputation: 719
I'm testing bunch of API calls using POSTMAN. Instead of adding authorization header to each request, can I make it as a part of POSTMAN environment? So, I don't have to pass it with every request.
Upvotes: 64
Views: 171723
Reputation: 323
A much simpler way is to use API Key
auth type for a collection.
It works for existing as well as new collections.
It lets you specify custom key and value which can be used as header as well as query params. Screenshot below:
Upvotes: 1
Reputation: 6641
In contemporary releases of Postman, you can just set your auth on the collection (or folder), and have every request inherit it (which I believe new requests do by default).
Upvotes: 22
Reputation: 854
Not sure if this is what you're looking for, but we use a link-based API that requires auth headers on each request. If you go to Postman > Preferences > General
and enable Retain headers when clicking on links
, Postman will pass through your auth headers to the child links.
Hope that helps!
Upvotes: 1
Reputation: 1791
If you can't wait here is a work around I just made:
var myHeader = {
"key": "X-Client-DN",
"value": "{{Postman-DN}}",
"description": "The User's DN Interacting with the system."
};
function addHeader(obj, header) {
if (obj.hasOwnProperty('request')) {
obj.request.header.push(myHeader)
}
if (obj.hasOwnProperty('item')) {
obj.item.forEach(function(element) {
element = addHeader(element, header);
});
}
return obj;
}
var a = {
"item": [{}, {
"request": {
"header": []
}
}, {
"item": [{
"request": {
"header": []
}
}]
}]
}
var b = addHeader(a, myHeader);
console.log(JSON.stringify(b, null, 2))
// Might have to run copy manually on console
//copy(b);
Upvotes: 0
Reputation: 2711
Yes, you can do this through Postman by assigning your header as an environment variable, let's say authorization
, as follow:
then set you environment variable with its value as follow:
Upvotes: 64
Reputation: 3241
postman usually remembers your key-value pairs you send in header. So there is no need to add headers each request. Anyway you can configure a "Preset" with your auth token.
Upvotes: 5