SharePoint 2016 REST API: query filtered by ContentType

Copper Contributor
Hi,
 
We're testing that our product properly supports SharePoint 2016, but we're having a problem with queries.
 
We've been using the REST API to retrieve the items from a list, filtered by type, as follows:
{server}/_api/lists(guid'29ca29ac-d10e-4285-9a80-9ed5c58cc0d6')/items?$filter=ContentType%20eq%20%27Task%27
In other words, filtering with the query "ContentType eq 'Task'". 
 
This worked with the 2013 version of the server, but the 2016 sever returns a 500 error: Internal Server Error: Column 'ContentType' does not exist. It may have been deleted by another user. (-2146232832, Microsoft.SharePoint.SPException)
 
We found that filtering by ContentTypeId (with a query such as "ContentTypeId eq '0x0108002840D046B700484FAC17F0F83950DFD7'") achieves what we want, but were hoping for a solution closer to the original, since using ContentTypeId is hard to read.
 
Is there a way of filtering by content type like what we did before?
 
Thanks!
 
 
8 Replies

Hi Gina,

 

So I think you'll need to modify your REST query just a bit.. 

 

In order to get the ContentType name you'll need to select it with $select=ContentType/Name&$expand=ContentType to get at the actual name value

 

Here's a working query that I have on a Library with Documents & Link to Document Content Types. I'm filtering to give me just the items that are Link to Document:

 

/_api/web/lists/getbytitle('DynProdFiles')/items?$select=Title,URL,ContentType/Name&$expand=ContentType&$filter=ContentType eq 'Link to a Document'

 

Good luck, let me know if that helps!

-Jared

 

@Gina Bolognesi just following up if my previous post was helpful?

Jared, I am running into the same issue as Gina did and I tried your suggestion. It did NOT work. Adding the filter to the query breaks it in SharePoint 2016

$filter=ContentType eq 'VideoContentType'

 

Do you have any suggestions? OR please let me know if someone else encountered this?

This is how my query looks like

 

/_api/Web/Lists/GetByTitle('Portal%20Content%20Library')/items?$select=ContentType/Name&$expand=ContentType&$filter=ContentType eq 'VideoContentType'

 

 

Hi Jared,

It does not work in SharePoint 2016. You get the same error - column 'ContentType' does not exists, even if you expand one.

Hi Gina,

 

Have you found any solution for this issue?. Because, I am also facing same issue in my SP2016 migration server.

 

Kindly let me know if you have found any solution.

 

Thanks in adv.

This has been fixed somewhere along the line by a cumulative update.

 

I noticed the issue on a SP2016 VM that had only been patched to FP2. Installing the most recent CU fixed the issue for me.

Thanks Cameron.

Issue has been fixed after installing CU. In MS updates blog also its mentioned.

Ref. below link ( Improvements and fixes section)  : Improvements and fixes