Wednesday, February 2, 2022

[SOLVED] Postman variables with unexpected breakline

Issue

Im trying to pass env. variables in postman request.

#1, Original request:

GET: https://default-api.me/v1/get_this <= This works fine

#2 If Im setting up like this:

GET: {{baseUrl}}/v1/get_this <= Not works

The difference in cURLis one breakline:

#1 Curl:

1    curl --location --request GET 'https://default-api.me/api/v1/calendars' \

#2 Curl:

1    curl --location --request GET 'https://default-api.me
2    /api/v1/calendars' \

In the #2 case there is a breakline exactly after the `{{baseUrl}}``

Any ideas, how can I remove that new line after the env. variables?


Solution

Your environment variable has a "\n" by mistake just remove everything and rewrite url:

  https://default-api.me/api/v1/calendars

and set the base url as :

enter image description here

you can also set the environment variable as :

set url first as:

url:

  {{baseurl}}/api/v1/calendars

then in prerequest:

pm.environment.set("baseUrl","https://default-api.me")

you can also just reset the variable by removing the extra \n as:

pm.environment.set("baseurl",pm.environment.get("baseurl").replace("\n","").replace("\r",""))


Answered By - PDHide
Answer Checked By - Gilberto Lyons (WPSolving Admin)