URL encodes Postman variable?

I use Postman to test REST APIs and parameterization tests with global variables.

I have to put the phone number in the GET: request /path/get?phone={{phone}}, but the leading +phone number will be interpreted as a space.

What is the syntax of URLs for encoding global variables in Postman? Is it possible to run JS encodeURIComponent()on a variable in a URL?

+22
source share
4 answers

Use Pre-request scripts(next to body) for this:

var encoded = encodeURIComponent({{phone number}});

or

var encoded = encodeURIComponent(postman.getEnvironmentVariable("phone number"));

and to continue use:

postman.setEnvironmentVariable("encoded phone number", encoded);

And set your url /path/get?phone={{encoded phone number}}

+31
source

,

    var encoded = encodeURIComponent(pm.environment.get("phone"));
    pm.environment.set("encoded phone number", encoded);
+3

, :

URL, . encodeURIComponent

.

enter image description here

0

Source: https://habr.com/ru/post/1675611/


All Articles