ODATA with a filter

Hi,

I am trying to use either the aurelia-fetch-client or aurelia-http-client to get do an ODATA filter over GET. The issue is that the url when the request is sent is encoded and the filter fails because the quotes get converted to %27. Is there a way to do this, or disable the urlencoding on the request?

An example url with a filter is ;
https://mywebsite.com/tables/items?$filter=(itemId eq ‘123456’)

When this is used with either the fetch or regular http client it the single quotes are replace with %27 so the odata filter fails as it needs these as single quote characters.

Any help is appreciated.

Hi. I have been using aurelia-fetch-client with asp.net web api using odata. If itemId is an integer you don’t need the single cuote marks like ‘123456’ . Just use ?$filter= itemId eq 12345. Same when using guids as key. You could try it first in Postman.

If you don’t understand my english please let me know so I will try to make myself understood.

Carlos

Carlos,

Thanks for the reply. I have been using postman and unfortunately even when trying to filter with a guid , you will need to use single quotes as a guid is seen as a string not an int. My data does use a guid for the id and not a regular int.

If not single cuote marks gets you an error en Postmat it is probably something different in our web.api. This is what I got. I hope it will help.

In my web.api .Net Framework 4.61 I am using this packages

Microsoft.AspNet.OData 6.1.0
Microsoft.Data.OData 5.8.2
Microsoft.OData.Core 7.2.0
Microsoft.OData.Edm 7.2.0

Sample Code

Model

public class Customer
{
public Guid CustomerId { get; set; }
public string CustomerName { get; set; }
}

Controller

using System.Web.Http;
using System.Web.OData;
using System.Web.OData.Routing;

public class CustomerController : ODataController
{
[HttpGet]
[EnableQuery()]
[ODataRoute(“Customer”)]
public IHttpActionResult GetAll()
{
List customers = new List();
customers.Add(new Customer { CustomerId = new Guid(“14cf2286-83cb-4171-9cb3-3138997a54a3”), CustomerName = “Carlos” });
customers.Add(new Customer { CustomerId = new Guid(“a3e722f9-65e4-44f7-8253-a3da62bc7b7f”), CustomerName = “Mentalengine” });

        return Ok(customers);
    }
}

WenApiConfig GetEdmModel()

builder.EntitySet<Customer>("Customer");

When using Postman

GET
http://localhost:64481/odata/Customer

Will Return:

{
@odata.context”: “http://localhost:64481/odata/$metadata#Customer”,
“value”: [
{
“CustomerId”: “14cf2286-83cb-4171-9cb3-3138997a54a3”,
“CustomerName”: “Carlos”
},
{
“CustomerId”: “a3e722f9-65e4-44f7-8253-a3da62bc7b7f”,
“CustomerName”: “Mentalengine”
}
]
}

GET
http://localhost:64481/odata/Customer?$filter= CustomerId eq a3e722f9-65e4-44f7-8253-a3da62bc7b7f

Will Return

{
@odata.context”: “http://localhost:64481/odata/$metadata#Customer”,
“value”: [
{
“CustomerId”: “a3e722f9-65e4-44f7-8253-a3da62bc7b7f”,
“CustomerName”: “Mentalengine”
}
]
}

BTH when trying using single cuote marks when filtering CustomerId I got an error.