SharePoint 2016 – REST API, stratswith and ContentTypeId

%3CLINGO-SUB%20id%3D%22lingo-sub-88960%22%20slang%3D%22en-US%22%3ESharePoint%202016%20%E2%80%93%20REST%20API%2C%20stratswith%20and%20ContentTypeId%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-88960%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20run%20into%20quite%20interesting%20issue.%20When%20you%20use%20REST%20API%20and%20want%20to%20filter%20results%20using%20ContentTypeId%20in%20document%20library%2C%20e.g.%20%24filter%3Dstartswith(ContentTypeId%2C%20%E2%80%980x0120%E2%80%99)%2C%20it%20works%20well%20until%20number%20of%20document%20reaches%20500%20items.%20Than%20you%20get%200%20results.%20Filter%20works%20fine%20when%20you%20compare%20exact%20content%20type%20Id%2C%20e.g.%20%24filter%3DContentType%2Beq%2B%E2%80%990x0120%E2%80%99.%3C%2FP%3E%3CP%3EAs%20it%20was%20mentioned%20in%20other%20conversation%2C%20you%20cannot%20filter%20on%20expanded%20ContentType%20(SP%202016%20only!)%3C%2FP%3E%3CP%3ESo%2C%20you%20can%20make%20RESTcall%20to%20library%20to%20get%20content%20type%20number%20from%20name%20and%20then%20use%20it%20in%20another%20query.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-89368%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20%E2%80%93%20REST%20API%2C%20stratswith%20and%20ContentTypeId%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-89368%22%20slang%3D%22en-US%22%3E%3CP%3EI%20will%20try%20that.%20Can%20work.%20Althought%20top%20and%20skips%20filters%20didn't%20work%20very%20well%20in%20SP2013%2C%20but%20maybe%20in%20SP2016...%3F%20Either%20way%2C%20it%20is%20worth%20to%20try.%20Thanks%20for%20suggestion.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-89367%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%202016%20%E2%80%93%20REST%20API%2C%20stratswith%20and%20ContentTypeId%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-89367%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20might%20be%20a%20threshold%20limit%20for%20%60starts%20with%60.%20Have%20you%20tried%20to%20get%20more%20with%20paging.%20Something%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet%20the%20first%20400%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24filter%3Dstartswith(ContentTypeId%2C%20%E2%80%980x0120%E2%80%99)%26amp%3B%24top%3D400%3C%2FPRE%3E%3CP%3EThen%20for%20the%20next%20page%20(400)%20go%20with%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24filter%3Dstartswith(ContentTypeId%2C%20%E2%80%980x0120%E2%80%99)%26amp%3B%24top%3D400%26amp%3B%24skip%3D400%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

We run into quite interesting issue. When you use REST API and want to filter results using ContentTypeId in document library, e.g. $filter=startswith(ContentTypeId, ‘0x0120’), it works well until number of document reaches 500 items. Than you get 0 results. Filter works fine when you compare exact content type Id, e.g. $filter=ContentType+eq+’0x0120’.

As it was mentioned in other conversation, you cannot filter on expanded ContentType (SP 2016 only!)

So, you can make RESTcall to library to get content type number from name and then use it in another query.

2 Replies
Highlighted

There might be a threshold limit for `starts with`. Have you tried to get more with paging. Something like:

 

Get the first 400:

 

$filter=startswith(ContentTypeId, ‘0x0120’)&$top=400

Then for the next page (400) go with:

 

 

$filter=startswith(ContentTypeId, ‘0x0120’)&$top=400&$skip=400

 

 

Highlighted

I will try that. Can work. Althought top and skips filters didn't work very well in SP2013, but maybe in SP2016...? Either way, it is worth to try. Thanks for suggestion.