Search code examples
urlodata

ODATA $expand and $select queries in url


Yes, I know, this question is always asked. But I looked for answers to my problem, and everything I've seen is the same explanation, but it still doesn't work for me. Explanations.

For example on the Northwind service (that I use to train because it is simple, before using my job's service) : https://services.odata.org/V2/Northwind/Northwind.svc/

If I do

It works.

BUT if I want to do : https://services.odata.org/V2/Northwind/Northwind.svc/Categories?$expand=Products($select=ProductName) (since there is a ProductName property in Products) ... It doesn't work. I have the error : Syntax error at position 9. That "position 9" corresponds to the first parenthesis.

However, all I have seen on http://odata.org/documentation and on StackOverflow's forum says it should be something like that. What do I wrong ?


Solution

  • I found. In odata v2, we need to expand the entity we want to display and then select out of parenthesis with the path relative to the basis entity.

    Example :

    https://services.odata.org/V2/Northwind/Northwind.svc/Categories?$expand=Products&$select=Products/ProductName

    It is not so weird after all...