SOLVED

Rest api search query --- Lookup field issue

Iron Contributor

I have a document library which has a custom field "Label" this Label field is a lookup field (to a list) multiple values allowed. For example my documentlibrary:

 

Title          Label

doc1         labelY, labelX

doc2         labelX

doc3         labelY, labelZ

 

Now I want to create a rest query to filter documents by Label

 

So far I have this:

https://blabla.sharepoint.com/sites/mike/label/_api/web/lists/getByTitle('Documents')/items?&select='Label%2cTitle%2cType'&refinementfilters='Label:contains('labelX')'

 

 

However, this gives me all documents in the library. So no filtering.

And when I check the xml result "Label" is referred as an ID to the list and not as "labelX"

 

What is wrong in my approach?

 

Thanks, Mike

 

 

5 Replies
Mike, don't have a ready of example of this, but you may have to "expand" it to get the Label text. By default, all you see is the ID.

For example, getting "more" fields for a user field is done like this:
<site>/_api/web/Lists(guid'<LIST ID>')/Items?$expand=PERSONFIELD&$select=*,PERSONFIELD/EMail

Hi @Brent Ellis

 

Great!! This works:

https://blabla.sharepoint.com/sites/mike/label/_api/web/lists/getByTitle('Documents')/items?$expand=Label&$select=*,Label/Title

But now I need to get it to the next level. I want to filter on "LabelX"

 

 

Something like this:

https://blabla.sharepoint.com/sites/mike/label/_api/web/lists/getByTitle('Documents')/items?$expand=Label&$select=*,Label/Title&refinementfilters='Label/Title eq ('labelX')

 

Any suggestions?

best response confirmed by Mike Jansen (Iron Contributor)
Solution
Haven't tested it, but it should work with the $filter:

/_api/web/lists/GetByTitle('Documents')/items?$select=*,Label/Title&$expand=Label&$filter=Label/Title eq 'labelX'

Let us know how it goes.

Hi @Luis Mañez, and @Brent Ellis,

 

Thank you both!! Found the solution.

Now make it some more dynamic but I can manage that.

 

For your information, this is my query:

 

 

https://blabla.sharepoint.com/sites/mike/label/_api/web/lists/getByTitle('Documents')/items?$select=*,Label/Title&$expand=Label&$filter=Label/Title eq 'labelX'&rowlimit=500

 

1 best response

Accepted Solutions
best response confirmed by Mike Jansen (Iron Contributor)
Solution
Haven't tested it, but it should work with the $filter:

/_api/web/lists/GetByTitle('Documents')/items?$select=*,Label/Title&$expand=Label&$filter=Label/Title eq 'labelX'

Let us know how it goes.

View solution in original post