Is it possible to encode the variables using Postman itself?
Ex :
{
"UserName": "Admin0011@test.com",
"Password": "test@123",
"ConfirmPassword": "test@123",
"Role": "SuperAdmin"
}
Is it possible to encode the password field using Postman itself and send it to the server? I am passing the above JSON data inside the body/header section.
Is it possible to do something like this inside Postman
base64UrlEncode(Password)
Right-click selected text, and choose EncodeURIComponent to manually encode a parameter value. To send a path parameter, enter the parameter name into the URL field, after a colon, for example :id . When you enter a path parameter, Postman will populate it in the Params tab, where you can also edit it.
Let us take an endpoint as https://postman-echo.com/basic-auth. The username for this endpoint is postman and the password is password. Next, to add the credentials in the encoded format we shall take the help of a third party application having the link − https://www.base64encode.org/.
8. Why does Postman mostly use Base64 encoding? Base64 encoding is widely used because it allows data to be transmitted in a textual format that is easier to send in HTML form statistics requests.
It's possible using Postman Pre-request Scripts and Postman Environment Variables .
First step is to set up the variables you want to encode.
Next, write a script. Postman has CryptoJs built-in, which you can use to encode strings. Here's a sample script to Base64 encode a string and set an environment variable to the encoded value:
var plainText = pm.environment.get('plainTextString');
var encoded = CryptoJS.enc.Base64.stringify(plainText);
console.log(`Encoded value: ${encoded}`) //if you want to see the value in the console
pm.environment.set("myEncodedRequestVariable", encoded);
Finally, use your encoded variables in the request body (or header) with this syntax:
{{myEncodedRequestVariable}}
Here is how I handle key/secret encoding for connecting to appigee ouath
let keys = pm.environment.get("key") + ":" + pm.environment.get("secret");
let encodedKeys = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(keys));
pm.environment.set("encodedKeys", encodedKeys);
Using just stringify as proposed by the currently accepted answer I got an odd error stating r.clamp is not a function. To fix that I had to parse the keys first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With