Environment variable value is ignored in the flow

I’ve created a simple flow with just one GET request with 9 variables. One of those variables is {{home_id_loop}} and it is used in the URL itself:

It is defined as an environment variable.

No matter how I change the value of that variable in the flow it is not reflected in the URL:

The resulting URL from the console is missing the parameter completely:

Any ideas? Thank you.

OS: Windows 10 (win32 10.0.19045, x64)
Postman version: 10.24.24
Postman UI version: 10.24.24-ui-240424-1153
Desktop platform version: 10.24.16

Hi @s-p-e-e-d-y

Your request looks correct, can you try deleting and re-creating the send request block with the request and trying again?

@s-p-e-e-d-y , Just some quick questions that might get you passed this. In the environment, for this variable, what do you see for the initial value and what do you see for the current value? I am guessing maybe you set the initial value, but the current value is blank.

Also, just a side questions, are you running this request as a single call or is this part of a monitor?

After extensive debugging, I found the issue.

My pre-request script calculates a signature using the URL. The script itself constructs the URL using the env variables available at that time and saves it in pm.request.url = pm.request.url.host + urlStr

And because flows don’t change the env variables, my URL was constructed incorrectly.

When I commented the above line the signature was not calculated correctly because it used the values from the environment and not from the flow.

It would be great to have access to flow variables (or some new type of variables?) from pre-request scripts. Otherwise, I don’t believe I can use flows for my API :slightly_frowning_face:

Hi @s-p-e-e-d-y

I’m glad you found the issue.

What’s the reason you’re doing as this as script? It might be possible to construct the URL in flows itself.

Hi Daniel,

I found the issue but not a solution :slight_smile:

I’m not sure I understand your question though. Let me try to explain what I’m doing:

  1. Pre-request script calculates a sha256 signature using different elements of the request, including the full URL.
  2. For that, the script is putting together the URL manually using the ENV variables.
  3. Any change of the URL parameter (e.g. {{home_id_loop}} in the Flow is not available in the pre-request script (because Flows do not update ENV variables).

In the end, I can’t find any way to calculate that signature while changing the URL parameters in the flow. I’m quite sure it’s not possible.

I hope that answers your question.

Hi @s-p-e-e-d-y

The Evaluate block has Typescript support and the crypto library available, however there isn’t currently a way to pull ENV variables outside out of the Send Request block and there is no way to update ENV variables with Flows at this time.

You can add the url components as constants on the Flows canvas and calculate the sha256 signature in the Evaluate Block and pass that into the requests.

I’ll bring this up with the team as a feature request regardless.

Thank you Daniel for the suggestion, I will take a look. I’m still new to Flows.

Also thank you for considering a feature request. Maybe having access to Flows variables from pre-request scripts would work. That way the requests will work both on their own (using ENV variables) and in the flow (using Flows variables). It will require only a simple check for the existence of the Flows variables in the script.

Just an idea :slight_smile:

1 Like