postman-app-support
postman-app-support copied to clipboard
Programmatically set the secret variable type
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'.
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
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.
:shipit: please
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
I would like to know as well
Same here...
Same...
+1 REQUIRED
+1
+1
+1
+1
+1
+1
+1
+1
+1
Same, this is a hard stop with us developing some of our new APIs.
same issue
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);
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')
});
+1 I would like this feature.
+1
+1
+1
Would love this feature
+1
+1 would like to have this feature
+1
+1
no news?
+5