loopback icon indicating copy to clipboard operation
loopback copied to clipboard

The where clause is not an object

Open subchal opened this issue 10 years ago • 2 comments

Hi Good evening

I have a model called "Favorites" and the findOne method is exposed through StrongLoop Explorer { "id": "string", "customerId": "string", "volunteereventsId": "string" }

When I invoke

http://sairamvolunteer.mybluemix.net/api/Favorites/findOne?filter=%7B%22where%22%3A%5B%22customerId%22%2C%22c8f5ecf6d7d5fde3a580c5029d79d505%22%5D%7D&access_token=JdwAlaPuNr8FondEc0HJ2AFF0XibAe5hvaF180iEDqDlkoYBPzpoinSp59Ofl7ma

I am getting the following error

{ "error": { "name": "Error", "status": 400, "message": "The where clause ["customerId","c8f5ecf6d7d5fde3a580c5029d79d505"] is not an object", "statusCode": 400 } }

I am not sure what I am doing incorrect with my where filter. Any guidance is greatly appreciated.

subchal avatar Jun 09 '16 01:06 subchal

@subchal : Your where filter syntax is wrong, it should be of following format: filter={"where":{"customerID:"your_id_value"}}

The API explorer accepts only a stringified JSON input in filter (see here) Above should resolve your issue. For future reference, please post your questions to our dedicated Questions' channels (links).

Closing this now. Thank you.

gunjpan avatar Jun 09 '16 14:06 gunjpan

I am having the same issue. We have a database which contains several companies, and each company can create several tags such that the Tags model has a foreign key property "companyId".

We created a middleware to always add a filter so that the user only sees their company's tags.

The problem is when calling GET /api/Tags, the req.filter.where clause must be an object. When calling /api/Tags/count, the req.filter.where must be a string, otherwise the count is for all the tags in the database, not just the current user's

frankorama avatar Sep 23 '16 15:09 frankorama