Forum Discussion

Mike Jansen's avatar
Mike Jansen
Iron Contributor
Mar 21, 2017

Rest api search query --- Lookup field issue

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

 

 

  • 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.
  • Brent Ellis's avatar
    Brent Ellis
    Silver Contributor
    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
    • Mike Jansen's avatar
      Mike Jansen
      Iron Contributor

      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?

      • Luis Mañez's avatar
        Luis Mañez
        MVP
        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.

Resources