Fragmented Thought

OData criteria encoding and 'Edm.Boolean' are not compatible issues

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

Did some work today with an OData system. Making n number of mistakes along the way, everything seemed normal, until I got to the this error message:

The types 'Edm.Boolean' and 'Edm.String' are not compatible.

It seemed to persist almost no matter what. The solution if you're here banging your head against the wall is pretty simple, if frustrating.

OData allows query like syntax. In its operational options, you can add things together such as {number} + {number}. So plus (+) is a very reserved character, and you sir or madam, are using it. I found this was the case only by dropping out of my prepared url param that looked like: criteria/targetUserID eq 'LANCGL' and seeing the cURL request itself. The resulting url came out: %24filter=criteria%2FtargetUserID+eq+%22LANCGL%22. All the encoding in the world did not damage, except for the + usage.

If you're using PHP, start searching your REST and cURL libraries for how the parameters are encoded onto the url. Somewhere, you're very likely to find http_build_query. The very last argument for that function allows your to swap to RFC3986, which encodes spaces with %20 instead of +. Do that, and you'll be gold.

http_build_query($options['data'], NULL, NULL, PHP_QUERY_RFC3986)