Search code examples
postmannewman

How to encode the variable present in query parameter in postman URL


I am using below code to encode the URL;

pm.request.url.query.each((q) => {
     q.update(encodeURI(q.toString()))
});

id=AUG|5f246f9b-7c97-4233-8de7-2d57f74cd86b|7.7305OAUGGwvjBwAAAAAIAgEAAAAAB7zTAAAAAAAAADEAAP..ZAAAAAD.....AAAAAAAAAAAAAAAAAAAAMTc3IHBhY2lmaWMgaHd5AAAAAAA-$15

Problem is with the pipe sign in the id. I have different id's for each environment hence I have to parameterize this. When I pass parameter in query parameter of API then above code doesn't decode and treat it like a string. How to pass query parameter as variable in above code?


Solution

  • Worked by using below;

     var encoded = encodeURIComponent(pm.environment.get("addressId"));