Postman Flow: APIs requests variable inheritance

Hi all, I have an important problem to ask you: I use Postman Flow for made an automatic test that involves some HTTP requests recalled in sequential order. The problem is: how can I handle the inheritance of a value generated in the Request1 (and used on its request body) and pass it to Request2 in Postman Flow? The same behavior works well in Postman Collection but with Flow the execution generates error because the value of the variable used by Request2 is “old”, is the same saved on Environment table. Here below some other informartions:

  1. Request1
    In the Pre-Request script there’re the below instructions and the variable is used on the input request correctly

…
pm.environment.set(“Param”, code);
…

  1. Request2
    In the input body, the variable generated before is used as {{Param}}, also in Flow the two blocks are correctly connected.

  2. Execution
    When I execute the Flow, {{Param}} value for Request1 changes correctly, but in Request2 the value is the old one saved on Environment table.
    I had try to put an “unset” function on the Post-Request script of the last request on the chain but it didn’t resolve…also I tried to use “pm.globals.set” but the value of {{Param}} is always the same.

In add, the behavior of the APIs with Collection section is Ok, so when I call Request1 and after Request2 that one inherits correctly the value from the first API.
Please, can you give me some type of help? Thank you very much for any kind of support.

Hi @lbaldon

Environments don’t work this way with Flows. They are for storing constants, not variables that will be changed (at this time).

For something like setting the Param value to be used in the future, you can either:

  1. If the Param value is an output of Request1 then you can pass it into Request2 directly on the Flows canvas
  2. Use the Evaluate Block with TypeScript to generate the value (instead of a pre-request script) and then you can pass it into the Send Request blocks directly or via a Flows variable.
  3. If neither of these is an option, you can work around the limitations by having your pre-request script in a request for the Postman Echo API https://postman-echo.com/get?param={{Param}} where Param is set the same way as in request1 right now. Then you can select that value returned by the API and pass it directly into subsequent requests:

Hi Daniel,
first of all, thank you for your kind reply.
The Param is dynamic and its used in Request1 not as an output but as an input (randomic), which has to be inherit by Request2
I tried to implement the Evaluate Block/TypeScript as your suggestion, but I don’t understand how to use it:

  • the Param, in Pre-Request script and now in Evaluate Block, contains a code to generate a random number
  • when I execute it, the Output returns “null”

  • I can’t connect correctly the Evaluate Block to the Request1 to use the parameter: in the case shown below, the Request1 “skip” the Evaluate Block, how can I told to Flow to use the code inside the block and reuse the value for other requests?

Sorry for the disturb, can I have your support also for these doubts?

Hi @lbaldon

Add code; as the final line in your evaluate block. The Evaluate Block with TS returns whatever the last evaluated value was.

That should fix your second issue as well.

Thanks again Daniel, I resolved with your suggestion to put the variable at the end of the TS Evaluate block.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.