Encode/Decode the variable/response using Postman itself

Dheeraj Gambhir
Feb 23, 2021

--

We get a lot of use cases where we may have to implement Base64 encoding and/or decoding while building our APIs. And, if you are wondering if it is possible to encode/decode the variable/response using Postman itself or how to encode/decode the token or password in postman and save it in a variable?

To Base64 encode/decode, the quickest way is to use JavaScript methods btoa, atob:

  • atob — It turns base64-encoded ASCII data back to binary.
  • btoa — It turns binary data to base64-encoded ASCII.

Sample code:

var responseBody = pm.response.json();

var parsedPwd = JSON.parse(atob(responseBody.password)); // presuming password is in the payload

pm.collectionVariables.set(“password”, parsedPwd);

--

--

No responses yet