How to filter response based on specific custom field?

Thanks, everyone.

When I get the response with this API https://reqres.in/api/users?page=2

I could see the response as below, but I would like to filter the data if email = “lindsay.ferguson@reqres.in”, could someone help here?

{
    "page": 2,
    "per_page": 6,
    "total": 12,
    "total_pages": 2,
    "data": [
        {
            "id": 7,
            "email": "michael.lawson@reqres.in",
            "first_name": "Michael",
            "last_name": "Lawson",
            "avatar": 
        },
        {
            "id": 8,
            "email": "lindsay.ferguson@reqres.in",
            "first_name": "Lindsay",
            "last_name": "Ferguson",
            "avatar": 
        },
        {
            "id": 9,
            "email": "tobias.funke@reqres.in",
            "first_name": "Tobias",
            "last_name": "Funke",
            "avatar": 
        },
        {
            "id": 10,
            "email": "byron.fields@reqres.in",
            "first_name": "Byron",
            "last_name": "Fields",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/russoedu/128.jpg"
        },
        {
            "id": 11,
            "email": "george.edwards@reqres.in",
            "first_name": "George",
            "last_name": "Edwards",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/mrmoiree/128.jpg"
        },
        {
            "id": 12,
            "email": "rachel.howell@reqres.in",
            "first_name": "Rachel",
            "last_name": "Howell",
            "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/hebertialmeida/128.jpg"
        }
    ]
}

Hey @Venkat.batchu81

It doesn’t look like that endpoint offers the ability to filter down the response, some endpoints would offer that capability via URL params. It looks like they have this for some items like page but not much else.

Depending on your use case you can still do this in a couple of ways with Postman. In the Tests tab, you can loop through the objects in the data array and log the one that contains the email address to the console

_.each(pm.response.json().data, (item) => {
    if(item.email === 'lindsay.ferguson@reqres.in') {
        console.log(item)
    }
})

I’ve also created a template, which can be imported directly into your Postman app, that uses the jsonpath syntax in the Visualizer to filter down the response data.

This would be something that you could use to filter down to an object containing a specific email address:

$..data[?(@.email=='lindsay.ferguson@reqres.in')]

2 Likes

Thanks @dannydainton , its working perfectly.

1 Like

Hi Danny,

I am working on something similar. I am very new to postman and I am not familiar with Javascript.

I am pulling the Etsy API on all active listings using a GET request: https://openapi.etsy.com/v2/listings/active

I want the listings that have views > 5000. How can I filter the results this way? Will I get the response in the Body?

Thank you

Have you tried any of the ways I mentioned?

Is there something that isn’t working for you?

You might need to expand on the information for anyone to help here. Not sure what the full response body is and where that particular views property is in the structure.

Hi Danny,

I am very new and learning postman so I am trying to understand the features.

I am learning how to use the Etsy API to get a list of all the active listings. However, there are over 50,100 active listings and I want the response to my GET request to spit out only listings with views > 5,000.

Views is not a parameter of the activelistings method but it is one of the properties (I am not sure if this the right terminology) of the response. I have attached the response. I am asking how I can filter so I can get a response that has only listings with views > 5,000

Thanks for your help.