How to add authorization header in POSTMAN environment?

眉间皱痕 提交于 2019-11-29 02:56:42

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:

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.

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).

If you can't wait here is a work around I just made:

  1. Export your collection (data format v2.1)
  2. Open firefox , dev tools, scratch pad
  3. Paste the code below
  4. Replace the header information with your header
  5. Replace the var a with your contents of the exported .json file
  6. Run the script
  7. The copy(b) command will put the new data with in your clipboard
  8. In postman, click import > Paste Raw Text > Import > as a copy.
  9. Verify your requests have your header, and run it :)

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);

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!