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);

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response