serlingpa
serlingpa

Reputation: 12660

LoopBack 3.0: where filter not returning results from REST API

I have a LoopBack API with a single simple model like this:

{
  "name": "Establishment",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "Distance": {
      "type": "number"
    },
    "EstablishmentId": {
      "type": "number"
    },
    "EstablishmentType": {
      "type": "string"
    },
    "Location": {
      "type": "string"
    },
    "MinCost": {
      "type": "number"
    },
    "Name": {
      "type": "string"
    },
    "Stars": {
      "type": "number"
    },
    "UserRating": {
      "type": "number"
    },
    "UserRatingTitle": {
      "type": "string"
    },
    "UserRatingCount": {
      "type": "number"
    },
    "ImageUrl": {
      "type": "string"
    },
    "ThumbnailUrl": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

A simple call to http://localhost:3000/api/Establishments returns all of the results, as expected; but a call to http://localhost:3000/api/Establishments?filter[where][distance][gt]=30 yields no results at all: an empty array.

There are lots of Establishments with a Distance greater than 30; and indeed using the where filter on other properties also results in an empty array. What could I be missing?

Upvotes: 0

Views: 118

Answers (1)

Anouar Kacem
Anouar Kacem

Reputation: 645

As I mentioned in the comment, it is case-sensitive and I varified it on my app to be certain about it.

it should be :

http://localhost:3000/api/Establishments?filter[where][Distance][gt]=30

or you can try with this format :

http://localhost:3000/api/Establishments?filter={"where":{"Distance":{"gt":30}}}

Upvotes: 0

Related Questions