Loops with external data

The basic design patterns discussed in the previous topic begin with iteration, then send each iteration's output to a Collect block.

In Postman, only the blocks within the sequences that include the For, Repeat, or Collect blocks are considered to be inside the loop. Any other blocks, whether connected to the inside blocks or not, are outside the loop.

This means the following:

  • List, Select, Number, String, and similar blocks that directly feed For or Repeat blocks in the sequence, and Display blocks connected to Collect blocks in the sequence, are inside the loop.

  • If you start with a design pattern that has one Evaluate block, and you add another, still in the sequence, both Evaluate blocks are within the loop.

  • If you insert Delay blocks between other blocks in the sequence, or attach Create Variable blocks to the outputs of blocks in the sequence, all of those blocks are within the loop.

  • If you add an HTTP Request block and it's not in between other blocks in the sequence, that block is outside the loop. This holds true even if you connect its output to the input of a block in the sequence.

Pin variables within your loops

A flow module won't iterate over any block that's outside the loop. Therefore, when a loop uses data from blocks outside the loop, it only retrieves that data once. There's no way for a block within the loop to iterate over such data.

To use a piece of data in this way, store it as an inline variable within a block that's inside the loop and pin the variable. Once pinned, the data is available to the inside block to iterate over. If you don't pin the variable, the block that's using it will run out of data, causing an error.

Notice the difference in appearance between an unpinned and a pinned variable:

Design pattern for basic loop with Repeat

Note that blocks can't change a variable's value. Variables keep their initial values through all of the loop's iterations. This means you can't use a variable in Flows the way you might use one in a "while do" loop coded in a programming language like Python or JavaScript.

Pin variables to store external data

You might want to use data other than what's in the list you're looping over. You can think of this additional data as external data, meaning external to the loop but still within Postman. You'll want to pin the external data.

For example, outside the sequence, an HTTP Request block might populate a Create Variable block. Then a block that's inside the sequence could retrieve that variable using an inline Get Variable block. The variable is considered external data because it originates from blocks that are outside the loop.

A loop that uses and pins external data is another Flows design pattern. For example, this works well for obtaining a new API token every time you run the flow.

It's also possible for a flow module to work with data outside of Postman, as explained in the Break out of a loop in Flows topic.

Build a loop that pins external data

You can use an HTTP request to obtain some information from an API or website, and send that information into a pinned variable within a Create with AI block. The AI block can then produce multiple texts, each of which considers what you stored in the pinned variable from a different perspective. You specify the perspectives as phrases in a list.

Here's an example of this kind of loop:

Design pattern loop that pins external data

To construct the loop, first create the outside blocks as follows:

  1. Connect an HTTP Request block to the Start block. In the image above it's a GET request to https://x-colors.yurace.pro/api/random. The response includes the hex notation for a color picked at random.

  2. Connect a Select block to the HTTP Request block's output and select the element of the response that you want your loop to use. (It may work better to navigate the HTTP Request block's output and click the desired element, then drag it to create the Select block. In the image above, the path is body.hex.)

  3. Connect a Create with AI block to the Select block's output and use it to translate the data into an appropriate English phrase. The Create with AI block in the image above, variable is renamed as colorInHex.

    Here are instructions used in the image above:

    Prompt for Create with AI block (click to expand)
     
    Compose a two-word name for the color {{colorInHex}}. The name should consist of an adjective followed by a one-word color name.
     
    Here are three examples:
     - "blood red"
     - "shocking pink"
     - "charcoal gray"
  4. Connect a Create Variable block to the Select block's output and name the variable. In the image above the variable name is colorName.

Next, create the inside blocks as follows:

  1. Create a List block and give it some strings as list items. In the image these are phrases that describe different categories of natural phenomena where the color described by the variable colorName might be found.

  2. Connect a For block to the List block.

  3. Connect a Create with AI block to the For block and give the input variable you connected it to a name that describes that list items. In the image, it's naturalPhenomena.

  4. Within the Create with AI block, add a variable and for its type, select a Get Variable block inline. Use the dropdown to select the variable you created outside the loop. In the image, the input variable is color and in the Get Variable block, colorName is selected.

  5. In the Get Variable block, click the pin icon, which will swivel to show that the variable is Pin icon pinned.

  6. In the AI block's text window, provide instructions for what you want the AI to do with the input text, incorporating variable names in your text.

    Here are the instructions used in the flow module above:

    Prompt for Create with AI block (click to expand)
     
    You are a scientist who studies {{naturalPhenomena}}.
     
    Write two sentences about one single particular living being or inanimate thing in your field of study whose coloration includes a color similar to {{color}}. Conclude with a third sentence that describes one emotion (not two or more emotions, only one) that {{color}} might evoke in people who see it.
     
    Only mention one living being or inanimate thing. Do not mention more than one.
    Only mention a being or thing that belongs to your area of study among {{naturalPhenomena}}. If you are talking about the plant kingdom do not mention an animal, for example.
    Begin the first sentence, "The color {{color}} is found in"
     
    When you mention {{color}}:
     - Never use the hex notation for {{color}}.
     - Only say the name of the color once, in the first sentence.
     - After that, when you want to refer to the color, do not cite its name, just say "this color".
     
    Do not quote the entire text of {{naturalPhenomena}}, just mention the being or thing in which {{color}} appears.
  7. Connect a Collect block to the last of the blocks from the previous step.

  8. Connect a Display block to the Collect block. From Settings icon Settings, under Display Type, choose Table.

Run the flow module. The AI will compose text according to your instructions.

Last modified: 2025/06/06