0

I have app in Backand that I'm building and I'm trying to use filter parameters. When calling my API using $http I get 406 error in the http request.

This would be the API call, passing the filter object:

function getUserAttractions(userId) {

  return $http({

    method: 'GET',

    url: Backand.getApiUrl() + '/1/objects/attractions',

    params: {

      sort: [{
        "fieldName": "date",
        "order": "asc"
      }],

      filter: [{
        "fieldName": "user_id",
        "operand": "contains",
        "value": "1"
      }]

    }

  });

}
Violet
  • 45
  • 5
  • 1
    There is no enough information - 406 comes from backend. So just check backend code and logs - what is received and why backend responded with 406 – Valentyn Shybanov Nov 30 '15 at 12:27
  • I think you should should check your backend, and maybe show some of it's code (that API method that handles this requests). – charliebrownie Nov 30 '15 at 12:46

2 Answers2

3

First, you should use "operator" instead of "operand". If user_id is an object field then the filter should be:

filter: [{"fieldName":"user_id","operator":"in","value":"1"}]

here you can find additional documentation for other types of fields http://docs.backand.com/en/latest/apidocs/apidescription/index.html#rest-api-crud-operations

Disclaimer: I work for Backand

relly
  • 439
  • 3
  • 3
1

With HTTP status 406 (Not Acceptable) the server is complaining that it cannot fulfill your request, probably because of your (missing) Accept header. See Wikipedia.

I don't know what your server is supposed to send, so I'm assuming it should send JSON in a response.

Try the following:

return $http({
    method: 'GET',
    url: Backand.getApiUrl() + '/1/objects/attractions',
    headers: {
        'Accept': 'application/json, */*'
    },
    params: {
        sort: [{"fieldName":"date","order":"asc"}],
        filter: [{"fieldName":"user_id","operand":"contains","value":"1"}]
    }
});

See AngularJS Page for more info.

jabu.10245
  • 1,884
  • 1
  • 11
  • 20