postman-app-support icon indicating copy to clipboard operation
postman-app-support copied to clipboard

Programmatically set the secret variable type

Open DannyDainton opened this issue 3 years ago • 35 comments

Is there an existing request for this feature?

  • [X] I have searched the existing issues for this feature request

Is your feature request related to a problem?

With the great addition of the secret variable type in the platform, users can now set the type manually through the UI but having the ability to set them via a script would round out the flow. By manually setting it, you would be exposing that 'secret' value to over the shoulder attacks until you have set the type and then hit save to mask the value.

The .set() function already has a 3rd optional arg for the type but as 'secret' isn't in the Variable Types it would fallback to 'default'.

Sandbox Environment

Describe the solution you'd like

Using the sandbox environment to set the variable type. A basic example of getting an access token value from a response body and then setting this as a secret variable:

let token = pm.response.json().access_token;
pm.environment.set('token', token, 'secret');

Describe alternatives you've considered

The Postman API can be used to programmatically set the type which could be done in a script using the pm.sendRequest() function but that seems a bit too long-winded to achieve what could be done in the set() function.

var options = {
  'method': 'PUT',
  'url': 'https://api.getpostman.com/environments/{{environment_uuid}}',
  'header': {
    'X-Api-Key': 'XXXX',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "environment": {
      "name": "Test Environment",
      "values": [
        {
          "key": "token",
          "value": "ABC123",
          "type": "secret"
        }
      ]
    }
  })

};
pm.sendRequest(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.json());
});

Additional context

No response

DannyDainton avatar Jan 18 '22 12:01 DannyDainton

Any updates? I have a script that takes secret keys from global variables in postman and creates their corresponding base64 encoded keys in global variables but I'm not able to mask them programmatically. They are created as plain text base64 encoded values.

YevheniiPokhvalii avatar Sep 23 '22 15:09 YevheniiPokhvalii

:shipit: please

andrhamm avatar Sep 28 '22 14:09 andrhamm

Hello to everyone 🙂

I am struggling with the same issue, I've search everywhere but I didn't found out any answers 🙁

Is there any workaround to fix this ?

Best regards

Vikmanatus avatar Oct 21 '22 18:10 Vikmanatus

I would like to know as well

lucianamerege avatar Nov 09 '22 17:11 lucianamerege

Same here...

shaike41 avatar Nov 15 '22 12:11 shaike41

Same...

umizu avatar Nov 17 '22 17:11 umizu

+1 REQUIRED

thomasinc avatar Nov 23 '22 23:11 thomasinc

+1

dan668061 avatar Dec 01 '22 01:12 dan668061

+1

makar-melikyan-wmg avatar Feb 03 '23 23:02 makar-melikyan-wmg

+1

nordquist avatar Mar 10 '23 08:03 nordquist

+1

gies74 avatar May 03 '23 10:05 gies74

+1

noead01 avatar May 12 '23 12:05 noead01

+1

ansghof avatar May 16 '23 15:05 ansghof

+1

F1ashhimself avatar May 27 '23 12:05 F1ashhimself

+1

CSaratakij avatar Aug 02 '23 03:08 CSaratakij

+1

WJones132 avatar Aug 15 '23 14:08 WJones132

Same, this is a hard stop with us developing some of our new APIs.

adamabernathy avatar Aug 18 '23 20:08 adamabernathy

same issue

dzarkV avatar Sep 02 '23 22:09 dzarkV

The suggestion in the description ☝️ was for something like:

let token = pm.response.json().access_token;
pm.environment.set('token', token, 'secret');

I would also be happy with a specific method called setSecret(...):

let token = pm.response.json().access_token;
pm.environment.setSecret('token', token);

evantoli avatar Sep 14 '23 23:09 evantoli

Facing the similar issue. Tried to set the type programmatically, no luck.

Any updates/solution on this?

pm.test("Management Access token is received and will be set as environment variable", () => {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('access_token');
    pm.environment.set('management_access_token', jsonData.access_token,'secret')
});

vishalmrode avatar Oct 10 '23 02:10 vishalmrode

+1 I would like this feature.

colin-stubbs avatar Oct 11 '23 09:10 colin-stubbs

+1

TianxiangR avatar Oct 13 '23 21:10 TianxiangR

+1

rhynzler avatar Oct 27 '23 21:10 rhynzler

+1

Would love this feature

stephen-mogensen avatar Nov 24 '23 19:11 stephen-mogensen

+1

irby avatar Nov 28 '23 22:11 irby

+1 would like to have this feature

adwaitsky avatar Dec 08 '23 16:12 adwaitsky

+1

TigranZalian avatar Dec 11 '23 21:12 TigranZalian

+1

leokdi avatar Feb 02 '24 14:02 leokdi

no news?

primax79 avatar Feb 08 '24 16:02 primax79

+5

BradCandell avatar Feb 13 '24 13:02 BradCandell