# How to get all combinations of 2 or more lists to 1 request?

**URL:** <https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864>\
**Category:** Help Hub\
**Tags:** loop, loops, postman-flows\
**Created:** [July 9, 2024, 8:18pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864 "2024-07-09T20:18:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elefantecinza](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@elefantecinza](https://community.postman.com/u/elefantecinza)\
**Post date:** [July 9, 2024, 8:18pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864/1 "2024-07-09T20:18:28Z")

</div>

Lets suppose we have 2 lists and a request that receives 2 variables

list1 = [a, b]  
list2 = [1, 2, 3]

request = {  
url = localhost:8080  
var1 = x  
var2 = y  
}

How can I send that request using all values combination for these 2 lists?

iteration1: x = a; y = 1  
iteration2: x = a; y = 2  
iteration3: x = a; y = 3  
iteration4: x = b; y = 1  
iteration5: x = b; y = 2  
iteration6: x = b; y = 3

In code, we would have something like this

for (x in list1) {  
\_\_\_for(y in list2) {  
\_\_\_\_\_\_sendRequest(localhost:8080, x, y)  
\_\_\_}  
}}

---

<div class="post-metadata">

**Author:** ![flows-daniel](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/flows-daniel/32/25516_2.png) [@flows-daniel](https://community.postman.com/u/flows-daniel)\
**Post date:** [July 9, 2024, 8:38pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864/2 "2024-07-09T20:38:44Z")

</div>

Hi @elefantecinza

Welcome to the forums!

You can combine the permutations of the two lists using TypeScript (enabled by clicking the drop down that says FQL on the top right corner of the Evaluate Block) in an Evaluate Block, then use a For Block to iterate through all the variables, passing in X and Y from the combined list like below:

 ![Screenshot 2024-07-09 at 1.36.00 PM](https://us1.discourse-cdn.com/getpostman/original/3X/b/c/bcb96ad48d7e3803216d20e9755f752daa468370.png)

TypeScript code for the Evaluate Block:

```auto
interface Combination {
  x: string;
  y: number;
}

const combinations: Combination[] = [];

for (const x of list1) {
  for (const y of list2) {
    combinations.push({ x, y });
  }
}
combinations;

```

---

<div class="post-metadata">

**Author:** ![elefantecinza](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@elefantecinza](https://community.postman.com/u/elefantecinza)\
**Post date:** [July 9, 2024, 8:50pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864/3 "2024-07-09T20:50:01Z")

</div>

I tried a lot of times and didnt get the solution. Thanks!

---

<div class="post-metadata">

**Author:** ![elefantecinza](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@elefantecinza](https://community.postman.com/u/elefantecinza)\
**Post date:** [July 9, 2024, 9:10pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864/4 "2024-07-09T21:10:21Z")

</div>

I dont know if I should open a new topic, but…

how the Evaluate block choose the result value to provide?

I mean… You didnt use a return statement to tell to the block that the variable “combinations” should be used as result of it

---

<div class="post-metadata">

**Author:** ![flows-daniel](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/flows-daniel/32/25516_2.png) [@flows-daniel](https://community.postman.com/u/flows-daniel)\
**Post date:** [July 9, 2024, 9:22pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864/5 "2024-07-09T21:22:28Z")

</div>

Hi @elefantecinza

Whatever the last value the script had will be returned. Hence why I put `combinations;` in the last line.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [July 12, 2024, 9:23pm UTC](https://community.postman.com/t/how-to-get-all-combinations-of-2-or-more-lists-to-1-request/63864/6 "2024-07-12T21:23:18Z")

</div>

Closed on July 12, 2024, 9:23pm UTC

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