# Compare Two Lists for matches. Extract key from matching index

**URL:** <https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051>\
**Category:** Help Hub\
**Tags:** key-value, search, loops, postman-flows\
**Created:** [August 13, 2024, 3:35pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051 "2024-08-13T15:35:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbrass137](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dbrass137](https://community.postman.com/u/dbrass137)\
**Post date:** [August 13, 2024, 3:35pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/1 "2024-08-13T15:35:49Z")

</div>

So I’m currently working to collect Engine hours from Samsara, then find the corresponding Meter in my MaintainX system, and update the hours for each meter.

I have succeeded in pulling the meters as a list, filtering for Forklifts only. I have also pulled the engine seconds given by Samsara and scaled them to hours and stored the name and hour values in a list. The issue I’m having is trying to get my Flow to scan through the Meters list to find a match for the Samsara index’s name value, then when/if a match is found send the hours for said index match forward. When the match occurs I would also need the Meter ID which is inside the Meters list. I tried using an Eval and now an If block to no real avail. Any help is greatly appreciated.

Top Flow line is for Samsara, and bottom is for MaintainX, both end in Collect blocks with the appropriate lists.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/1/e1ca752f19c21524eafeb1d960a6ad2101460f24.png)

---

<div class="post-metadata">

**Author:** ![dbrass137](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dbrass137](https://community.postman.com/u/dbrass137)\
**Post date:** [August 13, 2024, 3:48pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/2 "2024-08-13T15:48:11Z")

</div>

Added note, the For Loop on the bottom section throws an error, but all the data collected is correct and valid. Ignore the error as it does not impact the end result I’m looking for.

MaintainX list structure:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/a/caf7a0e61fec79da436e2a2e4bcc5bbfe203346a.png)

Samsara list structure:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/1/d19733a034767303668e42e30c1d8e3084f687d8.png)

---

<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:** [August 13, 2024, 8:56pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/3 "2024-08-13T20:56:07Z")

</div>

Hi @dbrass137

Welcome to the forums!

Once you have your two lists from the collect blocks, it will be easier to just perform the logic directly in an Evaluate Block from there.

I tried to recreate the shape of your data, so please try this solution:

```auto
Samsara.map((samsaraItem) => ({
  eh: samsaraItem.eh,
  id: MaintainX.find((maintainXItem) =>
    maintainXItem.asset.name.includes(samsaraItem.name)
  ).id
}));

```

 ![Screenshot 2024-08-13 at 1.55.00 PM](https://us1.discourse-cdn.com/getpostman/original/3X/e/1/e1fb70842e495670a64ba1350610cc01b73cc797.png)  
It should give you the final list

---

<div class="post-metadata">

**Author:** ![dbrass137](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dbrass137](https://community.postman.com/u/dbrass137)\
**Post date:** [August 13, 2024, 10:04pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/4 "2024-08-13T22:04:16Z")

</div>

@flows-daniel

First off, THANK YOU! I have been getting beaten by this all day and this solution worked! Only have one hang up now, for some reason the Samsara data of eH (the engine hours) is passed into everything in orange text and is treated as a number/int the whole time until I use the provided MaintainX API POST to send it in. I keep getting an error stating that it “must be a number”, and the fail output on that block shows it in green like a string. Do I need to define the value type in the body text or something?

Error I’m getting:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/a/fad21f9160aaf3b1d0ccdaef9f45e52102db1046.png)

Previous block shows it as a number:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/8/086130be9476edd60592cb1f28703f84807bdf93.png)

---

<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:** [August 13, 2024, 11:49pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/5 "2024-08-13T23:49:15Z")

</div>

@dbrass137

Glad to hear the solution helped 🙂

what does your request body look like right now before the variables are filled and what is shown in the console for this request?

If you’re wrapping the variable names in quotes in your body request it will be treated as a string.

---

<div class="post-metadata">

**Author:** ![dbrass137](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@dbrass137](https://community.postman.com/u/dbrass137)\
**Post date:** [August 13, 2024, 11:59pm UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/6 "2024-08-13T23:59:21Z")

</div>

![Paris_Tuileries_Garden_Facepalm_statue](https://us1.discourse-cdn.com/getpostman/original/3X/9/4/94b03614f32882f40f1953458410ca7ba9cb43e8.jpeg)

Okay, wow. So yes, I did have quotes around that variable in the body. Leftovers from before it was a variable. You are the best Thank you @flows-daniel

---

<div class="post-metadata">

**Author:** ![lunar-module-1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/lunar-module-1/32/26132_2.png) [@lunar-module-1](https://community.postman.com/u/lunar-module-1)\
**Post date:** [August 14, 2024, 11:05am UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/7 "2024-08-14T11:05:30Z")

</div>

> [@dbrass137](#):
>
> First off, THANK YOU! I have been getting beaten by this all day and this solution worked!

Thank you for sharing this flow, there are lots of worthwhile observations for us for areas we can improve. I’m happy Daniel helped you resolve the issues. Please continue to share you feedback with us, we’re listening and taking notes on how to make things easier.

---

<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:** [September 13, 2024, 11:05am UTC](https://community.postman.com/t/compare-two-lists-for-matches-extract-key-from-matching-index/66051/8 "2024-09-13T11:05:57Z")

</div>

Closed on September 13, 2024, 11:05am UTC

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