Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding variables using Postman

Is it possible to encode the variables using Postman itself?

Ex :

{
  "UserName": "[email protected]",
  "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) 
like image 971
Harsha W Avatar asked May 08 '17 09:05

Harsha W


People also ask

How does a Postman encode a value?

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.

How do I encode my Postman?

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

Why is base64 encoding primarily used in Postman?

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.


Video Answer


2 Answers

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}} 
like image 165
paulyb Avatar answered Sep 20 '22 21:09

paulyb


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.

like image 25
Nox Avatar answered Sep 16 '22 21:09

Nox