# Checking that an ID is appearing or not in my Response Body

**URL:** <https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [July 1, 2021, 6:23am UTC](https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377 "2021-07-01T06:23:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdrianChirion](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@AdrianChirion](https://community.postman.com/u/AdrianChirion)\
**Post date:** [July 1, 2021, 6:23am UTC](https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377/1 "2021-07-01T06:23:12Z")

</div>

Hello,

I am using an API to add and delete movies from a list, I’m using postman collection variables to take the id of the new movie I added so that I can use it in some tests. Here is an example of what the list of movies looks like:

[  
{

```
    "actors": "Kevin Zegers, Rip Torn",

    "category": "Popular",

    "director": "Peter Hewitt",

    "genres": "Action, Adventure, Family, Sci-Fi",

    "id": 1457,

    "imdb": "https://www.imdb.com/title/tt0383060/",

    "language": "English",

    "minutes": 83,

    "rating": 4,

    "stock": 3,

    "title": "Zoom",

    "year": 2006

},

{

    "actors": "Orlando Bloom, Tanya van Graan",

    "category": "Regular",

    "director": "Jérôme Salle",

    "genres": "Crime, Drama, Thriller",

    "id": 2516,

    "imdb": "https://www.imdb.com/title/tt2249221/",

    "language": "English",

    "minutes": 110,

    "rating": 3,

    "stock": 2,

    "title": "Zulu",

    "year": 2013

}

```

]

Using the last entry with an id of 2516 as an example, I want the test to either log that the movie exists in the list based on its id or if it doesn’t exist. So far I have tried this but it doesn’t quite work:

if(pm.response.text().includes(pm.collectionVariables.get(“idData”)) === true) {

```
console.log("Movie exists within the list");

```

}

else {

```
console.log("Movie no longer exists in the list")

```

}

I’m sure I’m doing something wrong or missing something. There’s probably a better way of doing it. I appreciate any help.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [July 1, 2021, 7:41am UTC](https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377/2 "2021-07-01T07:41:47Z")

</div>

@AdrianChirion Welcome to the Community 🥳

Can you please check the [similar post](https://community.postman.com/t/how-can-i-search-the-entire-response-for-a-specific-value/25264) discussed here?

---

<div class="post-metadata">

**Author:** ![AdrianChirion](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@AdrianChirion](https://community.postman.com/u/AdrianChirion)\
**Post date:** [July 1, 2021, 8:57am UTC](https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377/3 "2021-07-01T08:57:26Z")

</div>

Thanks for the response!

I tried applying that solution but I kept getting the error ‘TypeError: Cannot read property ‘0’ of undefined’

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [July 1, 2021, 10:10am UTC](https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377/4 "2021-07-01T10:10:13Z")

</div>

You make sure to give your path correctly based on your response 😊

[This post](https://bpricilla.medium.com/how-to-easily-locate-your-json-object-in-your-api-response-647549ee8b2) might help you to locate your path using [https://jsonpathfinder.com/](https://jsonpathfinder.com/)

---

<div class="post-metadata">

**Author:** ![AdrianChirion](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@AdrianChirion](https://community.postman.com/u/AdrianChirion)\
**Post date:** [July 1, 2021, 11:46am UTC](https://community.postman.com/t/checking-that-an-id-is-appearing-or-not-in-my-response-body/25377/5 "2021-07-01T11:46:44Z")

</div>

I managed to get it working! Thank you so much!
