SharePoint 2016 REST API: query filtered by ContentType

%3CLINGO-SUB%20id%3D%22lingo-sub-51946%22%20slang%3D%22en-US%22%3ESharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-51946%22%20slang%3D%22en-US%22%3E%3CDIV%3E%3CFONT%20color%3D%22%23000000%22%3EHi%2C%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EWe're%20testing%20that%20our%20product%20properly%20supports%20SharePoint%202016%2C%20but%20we're%20having%20a%20problem%26nbsp%3Bwith%20queries.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20color%3D%22%23000000%22%3EWe've%20been%20using%20the%20REST%20API%20to%20retrieve%20the%20items%20from%20a%20list%2C%20filtered%20by%20type%2C%20as%20follows%3A%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22monospace%2C%20monospace%22%20color%3D%22%23000000%22%3E%7Bserver%7D%2F_api%2Flists(guid'29ca29ac-d10e-4285-9a80-9ed5c58cc0d6')%2Fitems%3F%24filter%3DContentType%2520eq%2520%2527Task%2527%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20color%3D%22%23000000%22%3EIn%20other%20words%2C%20filtering%20with%20the%20query%20%22%3CFONT%20face%3D%22monospace%2C%20monospace%22%3EContentType%20eq%20'Task'%3C%2FFONT%3E%22.%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20color%3D%22%23000000%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20color%3D%22%23000000%22%3EThis%20worked%20with%20the%202013%20version%20of%20the%20server%2C%20but%20the%202016%20sever%20returns%20a%20500%20error%3A%26nbsp%3B%3CFONT%20face%3D%22monospace%2C%20monospace%22%3EInternal%20Server%20Error%3A%20Column%20'ContentType'%20does%20not%20exist.%20It%20may%20have%20been%20deleted%20by%20another%20user.%26nbsp%3B%3CA%20href%3D%22tel%3A(214)%2520623-2832%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E(-2146232832%3C%2FA%3E%2C%20Microsoft.SharePoint.SPException)%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22monospace%2C%20monospace%22%20color%3D%22%23000000%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSPAN%3E%3CFONT%20face%3D%22arial%2C%20helvetica%2C%20sans-serif%22%3EWe%20found%20that%20filtering%20by%20ContentTypeId%20(with%20a%20query%20such%20as%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22monospace%2C%20monospace%22%3E%22ContentTypeId%20eq%20'0x0108002840D046B700484FAC17F0F83950DFD7'%22)%3C%2FFONT%3E%3CFONT%20face%3D%22arial%2C%20helvetica%2C%20sans-serif%22%3E%26nbsp%3Bachieves%20what%20we%20want%2C%20but%20were%20hoping%20for%20a%20solution%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3CFONT%20face%3D%22arial%2C%20helvetica%2C%20sans-serif%22%3E%3CSPAN%3Ecloser%20to%20the%20original%2C%20since%20using%20ContentTypeId%20is%20hard%20to%20read.%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22monospace%2C%20monospace%22%20color%3D%22%23000000%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22arial%2C%20helvetica%2C%20sans-serif%22%20color%3D%22%23000000%22%3EIs%20there%20a%20way%20of%20filtering%20by%20content%20type%20like%20what%20we%20did%20before%3F%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22arial%2C%20helvetica%2C%20sans-serif%22%20color%3D%22%23000000%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22arial%2C%20helvetica%2C%20sans-serif%22%20color%3D%22%23000000%22%3EThanks!%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-51946%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-225031%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-225031%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20Cameron.%3C%2FP%3E%3CP%3EIssue%20has%20been%20fixed%20after%20installing%20CU.%20In%20MS%20updates%20blog%20also%20its%20mentioned.%3C%2FP%3E%3CP%3ERef.%20below%20link%20(%20Improvements%20and%20fixes%20section)%26nbsp%3B%20%3A%20%3CA%20title%3D%22Improvements%20and%20fixes%22%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4011680%2Fdescriptionofthesecurityupdateforsharepointentserver2016february13-201%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EImprovements%20and%20fixes%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-224197%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-224197%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20has%20been%20fixed%20somewhere%20along%20the%20line%20by%20a%20cumulative%20update.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20noticed%20the%20issue%20on%20a%20SP2016%26nbsp%3BVM%20that%20had%20only%20been%20patched%20to%20FP2.%20Installing%20the%20most%20recent%20CU%20fixed%20the%20issue%20for%20me.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215757%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215757%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Gina%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20you%20found%20any%20solution%20for%20this%20issue%3F.%20Because%2C%20I%20am%20also%20facing%20same%20issue%20in%20my%20SP2016%20migration%20server.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKindly%20let%20me%20know%20if%20you%20have%20found%20any%20solution.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20adv.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-88957%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-88957%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Jared%2C%3C%2FP%3E%3CP%3EIt%20does%20not%20work%20in%20SharePoint%202016.%20You%20get%20the%20same%20error%20-%20column%20'ContentType'%20does%20not%20exists%2C%20even%20if%20you%20expand%20one.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-83268%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-83268%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20how%20my%20query%20looks%20like%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F_api%2FWeb%2FLists%2FGetByTitle('Portal%2520Content%2520Library')%2Fitems%3F%24select%3DContentType%2FName%26amp%3B%24expand%3DContentType%26amp%3B%24filter%3DContentType%20eq%20'%3CSPAN%3EVideoContentType%3C%2FSPAN%3E'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-83266%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-83266%22%20slang%3D%22en-US%22%3E%3CP%3EJared%2C%20I%20am%20running%20into%20the%20same%20issue%20as%20Gina%20did%20and%20I%20tried%20your%20suggestion.%20It%20did%20NOT%20work.%20Adding%20the%20filter%20to%20the%20query%20breaks%20it%20in%20SharePoint%202016%3C%2FP%3E%3CP%3E%24filter%3DContentType%20eq%20'VideoContentType'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20you%20have%20any%20suggestions%3F%20OR%20please%20let%20me%20know%20if%20someone%20else%20encountered%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-55428%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-55428%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F42970%22%20target%3D%22_blank%22%3E%40Gina%20Bolognesi%3C%2FA%3E%26nbsp%3Bjust%20following%20up%20if%20my%20previous%20post%20was%20helpful%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-52336%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20REST%20API%3A%20query%20filtered%20by%20ContentType%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-52336%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Gina%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20think%20you'll%20need%20to%20modify%20your%20REST%20query%20just%20a%20bit..%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20order%20to%20get%20the%20ContentType%20name%20you'll%20need%20to%20select%20it%20with%20%24select%3DContentType%2FName%26amp%3B%24expand%3DContentType%20to%20get%20at%20the%20actual%20name%20value%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere's%20a%20working%20query%20that%20I%20have%20on%20a%20Library%20with%20Documents%20%26amp%3B%20Link%20to%20Document%20Content%20Types.%20I'm%20filtering%20to%20give%20me%20just%20the%20items%20that%20are%20Link%20to%20Document%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F_api%2Fweb%2Flists%2Fgetbytitle('DynProdFiles')%2Fitems%3F%24select%3DTitle%2CURL%2CContentType%2FName%26amp%3B%24expand%3DContentType%26amp%3B%24filter%3DContentType%20eq%20'Link%20to%20a%20Document'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGood%20luck%2C%20let%20me%20know%20if%20that%20helps!%3C%2FP%3E%3CP%3E-Jared%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor
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
Highlighted

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

 

Highlighted

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

Highlighted

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?

Highlighted

This is how my query looks like

 

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

 

 

Highlighted

Hi Jared,

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

Highlighted

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.

Highlighted

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.

Highlighted

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