无法在 MS Graph API 中按内容类型过滤列表项

huangapple go评论57阅读模式
英文:

Can't filter list item by Content Type in MS Graph API

问题

我试图通过MS Graph API在搜索SharePoint列表时筛选项目,其中满足某些自定义字段值,并且内容类型不是文件夹。例如:

/sites/mysite.sharepoint.com/lists/test/items?&select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/MyColumn eq 'HelloWorld' and fields/ContentType ne 'Folder'

我已经对自定义字段和内容类型进行了索引,但仍然收到以下错误:

{
    "error": {
        "code": "invalidRequest",
        "message": "字段'ContentType' 不能在筛选或排序中引用,因为它没有被索引。提供'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly'头部以允许此操作,但请注意,这样的查询可能会在大型列表上失败。"
    }
}

我已经使用上述的"Prefer"头部,它确实返回了数据,但似乎不应该在自定义字段已被索引的情况下提供这样的值。我是否遗漏了某些东西,或者MS Graph API中的内容类型列存在兼容性问题?如果存在问题,我如何绕过它,而不必使用"Prefer"头部?

英文:

I am trying to filter items when searching a SharePoint list, via the MS Graph API, where certain custom field values are met, and the content type is not a folder. For example:


/sites/mysite.sharepoint.com/lists/test/items?&select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/MyColumn eq 'HelloWorld' and fields/ContentType ne 'Folder'

I have both the custom field and Content Type indexed, but I still receive:

{
    "error": {
        "code": "invalidRequest",
        "message": "Field 'ContentType' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists."
    }
}

I have used the above Prefer header and that does return data, but seems wrong that I have to supply such a value when the column is indexed. Is there something I am missing with this or is there a compatability problem with the Content Type column within the MS Graph API? If there is, how can I work around it without having to use the Prefer header?

答案1

得分: 0

https://graph.microsoft.com/v1.0/sites/{站点 ID}/lists/{列表 ID}/items?$select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/MyColumn eq 'HelloWorld' and fields/ContentType ne 'Folder'

Prefer: allowthrottleablequeries

英文:

You need to provide the allowthrottleablequeries preference to execute this query, so you must provide request headers for this endpoint.

https://graph.microsoft.com/v1.0/sites/{site id}/lists/{list id}/items?$select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/MyColumn eq 'HelloWorld' and fields/ContentType ne 'Folder'

Prefer: allowthrottleablequeries

huangapple
  • 本文由 发表于 2023年2月6日 20:23:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75361273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定