REST to filter on a FieldUrlValue

Copper Contributor

Hello

 

I am trying to filter a list based on the Url value in a SP.FieldUrlValue using REST. I tried to use the expand odata command but this did not work. If I select the field in the REST call it returns the whole value unlike a People field that requires expanding. Does this therefore mean it is not possible?

 

Example of what I have tried but to no avail

  • https://thesiteiamtestingagainst/sites/test/_api/web/lists/getbytitle('Comments')/items?$select=URL&$filter=URL eq 'http://www.bbc.co.uk'
  • https://thesiteiamtestingagainst/sites/test/_api/web/lists/getbytitle('Comments')/items?$select=URL&$filter=URL/Url eq 'http://www.bbc.co.uk'$expand=URL/Url

NOTE: I have tried both examples without the single quotes around http://www.bbc.co.uk and with Double Quotes

 

I have attached an image of the field in a reponse form REST it I select all items

 

Thanks in advance

 

Ben

 

6 Replies

Hi

 

A couple of weeks ago I was doing similar things with a SPD site workflow for my client. I understand how fustrating the syntax is .  Make sure your response evelope is json with a request header 

accept=application/json;odata=verbose

You need to wrap brackets around your filter clause. -

  

https://thesiteiamtestingagainst/sites/test/_api/web/lists/getbytitle('Comments')/items?$filter=(URL eq 'http://www.bbc.co.uk')
https://thesiteiamtestingagainst/sites/test/_api/web/lists/getbytitle('Comments')/items?slect=URL&$filter=(URL eq 'http://www.bbc.co.uk')

 

I think you need to get data out of your response evelope with a path similar to 

 

d/results 

 

Thereafter you can pick the values with the desired path - you will need to confirm this a tool like Postman.

 

Good luck

 

 

Would suggest to get the caml query builder where it puts out the correct code and URL.

 

kr,

 

Paul

Thank you for your reply Daniel

 

Unfortunately this returns the following when I tried it.

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-1, Microsoft.SharePoint.SPException</m:code>
<m:message xml:lang="en-US">
The field 'URL' of type 'URL' cannot be used in the query filter expression.
</m:message>
</m:error>

Maybe you cannot filter on the URL column type via REST?

Thank you for your reply Pieter

 

This article relates to filtering via field called URL that is not a SP.FieldUrlValue type field but a text field. This would work but I need to filter on the SP.FieldUrlValue type

Thank you for your reply Paul

 

I download both the U2U Caml builder and the RR Caml Builder form Codeplex (Latest version on Git) but while it shows me the Caml to use it does not give me the REST call. Within the Caml it specifies the type of URL.

 

Where you refering to Caml builder tool that also puts out the REST call for the query? If so where is this available to download?