Populate with filtering

[details=“System Information”]

  • Strapi Version- Starpi V4:
  • Operating System - Windows 10:
  • Database- Mysql:
  • Node Version - v14.15.1:
  • NPM Version-7.5.3:

I want to populate a data with filteration. I have two content-types

  1. Deal
  2. User

Relationship : User has many deals (one to many)

I want to have number of deals created by a particular user.

MY Example JSON Data, this I am getting by calling API : http://localhost:1337/api/deals?populate=user

 {
            "id": 1,
            "attributes": {
                "dealTitle": "Musical Instrument",
                "dealDescription": "20% off on guitars",
                "dealActualPrice": 5000,
                "dealDealPrice": 4000,
                "dealDate": "2022-01-10T21:45:00.000Z",
                "dealStartTime": "2022-01-11T18:30:00.000Z",
                "dealEndTime": "2022-01-12T18:30:00.000Z",
                "country": "India",
                "stateVal": "Chhattishgarh",
                "address": "abc aprtments",
                "address2": "unit 3 ",
                "city": "Raipur",
                "zipcode": "490010",
                "createdAt": "2022-01-11T07:47:30.138Z",
                "updatedAt": "2022-01-11T07:47:31.763Z",
                "publishedAt": "2022-01-11T07:47:31.751Z",
                "user": {
                    "data": {
                        "id": 1,
                        "attributes": {
                            "username": "Joe123",
                            "email": "joe123@com.com",
                            "provider": "local",
                            "confirmed": true,
                            "blocked": false,
                            "createdAt": "2022-01-11T07:48:59.125Z",
                            "updatedAt": "2022-01-11T07:52:27.478Z",
                            "phone": "7896541230",
                            "country": "India",
                            "stateVal": "Chandigarh",
                            "address": "abc apartment",
                            "address2": "unit 2",
                            "city": "Raipur",
                            "zipcode": "491001"
                        }
                    }
                }
            }
        }

To filter it in relationship level I used API URL as : http://localhost:1337/api/deals?populate[user][filters][username][$eq]=Joe123,

I’m getting all the deals with user data as null :-

 {
            "id": 4,
            "attributes": {
                "dealTitle": "Glass Shop",
                "dealDescription": "GLass sheet at 40% flat discount. ",
                "dealActualPrice": 5500,
                "dealDealPrice": 3300,
                "dealDate": "2022-01-04T10:23:16.000Z",
                "dealStartTime": "2021-12-07T09:30:00.000Z",
                "dealEndTime": "2022-01-11T14:48:00.000Z",
                "country": null,
                "stateVal": null,
                "address": null,
                "address2": null,
                "city": null,
                "zipcode": null,
                "createdAt": "2022-01-11T09:24:43.127Z",
                "updatedAt": "2022-01-11T09:24:43.127Z",
                "publishedAt": "2022-01-11T09:24:43.124Z",
                "user": {
                    "data": null
                }
            }
        }

My expected Output is : number of deals created by user=“Joe123”

Please help :flushed: :pleading_face:

I think this should work for you:
http://localhost:1337/api/deals?populate=user&filters[user][username][$eq]=Joe123

1 Like

Thankyou so so much! it worked!