none
SharePoint 2016 REST API: query filtered by ContentType RRS feed

  • Question

  • 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!

    Wednesday, March 8, 2017 11:26 PM

All replies

  • Hi,

    Here are two workarounds for your reference currently:

    Select content type and expand name by rest API like below, and then filter task item by content type name.

    _api/Web/Lists/getByTitle('MyTasks')/items?$select=ContentTypeId,ContentType/Name&$expand=ContentType

    Or create a simple workflow to copy content type name to custom field( use ‘Call HTTP Web Service’ to get content type name by above rest api ) and then filter tasks by custom field.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, March 10, 2017 9:28 AM