How to programmatically set Authorization tab selections

How does one programmatically set selections under the Authorization tab? Here’s the scenario:

  1. Request A1(of a collection) requires Authorization->NTLM. Request B(of a different collection) requires Authorization->Bearer Token.
  2. Looking for a programmatic way to auto configure either NTLM or Bearer Token based on a specified env variable or another method. The idea is to toggle selection under Authorization tab programmatically.

Thanks.

Hey @gszePM! Welcome to the Postman Community :tada:

As I understand it, you would like to set authorization type in scripts, correct?

Can you check out the following thread if that answers your question?

Hope this helps! :smiley:
Please let me know if you have further questions!

Hi taehoshino:

Please provide example/usage code. Getting the following errors(~)in the pre-request:

image002.jpg

Hey @gszePM,

You would need double-quotation around {{Username}} and {{Password}}.

Hope this helps!

  1. Still getting syntax errors after adding double quotes:
    [//discourse-cloud-file-uploads.s3.dualstack.us-west-2.amazonaws.com/business6/uploads/getpostman/original/2X/8/8bd101a7a5e756a629a756f3b42d948576196964.jpeg]

  2. Will using “authorizeUsing(type)” or upsertHeader() call change selection under Authorization tab display – for example: current Authorization is “NTLM…” and if use method call to “Basic” will Authorization tab entry show “Basic”. In my experiment using

var sToken = "Bearer " + pm.globals.get(“GatewayToken”);
pm.test("sToken is: " + sToken);
pm.request.upsertHeader({“Authorization”: sToken});

the Authorization tab entry did not change to “Bearer token” .

image002.jpg