Pre request decode is not working


I decode config params and I update the uri, but the decode is not applied.

Hey @tom.112

Welcome to the community! :star:

I’m not sure what you’re trying to do here but to replace the query param value for the request you would need to use:

pm.request.url.query.upsert({key: "paramName", value: "paramValue"})
1 Like

upsert doesn’t help.

upert is same with “add”.

Is any other way to update params value ?

Hey @tom.112 when you say upsert doesn’t help? What exactly didn’t work?

Was the parameter value not update in your case? Or is there something else you were expecting that didn’t happen?

I’m taking a wild guess here and assuming you are expecting the data not to be encoded? If that’s the case, the RFC states these must be encoded and since ‘#’ is reserved for fragment identifiers, it is encoded before being included as the parameters value

If data for a URI component would conflict with a reserved
character’s purpose as a delimiter, then the conflicting data must be
percent-encoded before the URI is formed.

Is there anything that can be set to not encode #?

upsert is slightly different that add, upsert will update an existing key if present or add a new one if it’s not. The add method would just add a new one.

Your syntax is slightly wrong in the code, it needs to be in an object with key and value properties.

pm.request.url.query.upsert({key: "config", value: decoded})
pm.request.url.query.upsert({key: "config", value: decoded})

Um, am I right?
um…I couldn’t solve it.

console.log(decoded) -> !@#$

pm…upsert({…}) -> !@%23$

First I changed it manually.

What is the expected outcome? What do you think the request should look like?

Do you have a hardcoded example of where you’re trying to achieve?

there is no example…so that’s why I quest in it.

  • now : GET http:// ~/~?config=!@%23$
  • expected outcome : GET http:// ~/~?config=!@#$


var decoded = decodeURIComponent(reqParameters.config);

console.log(decoded); -> “!@#$” ok

pm.request.url.query.upsert({key : “config”, value : decoded}); -> !@%23$ failed