[英]Microsoft graph Api get sharepoint list items, found no item using query $filter=indexOf or $search
I am trying to get list items from SharePoint list by searching the title of the item with specific keywords.我正在尝试通过使用特定关键字搜索项目的标题来从 SharePoint 列表中获取列表项。 But I got stuck in using Graph API query parameter $filter or $search.
但我被困在使用 Graph API 查询参数 $filter 或 $search。
https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items?
$select=id
&$expand=fields($select=id,title)
[{
"fields": {
"id": "1",
"Title": "由工作触发的私聊和群聊"
}
},
{
"fields": {
"id": "2",
"Title": "在地图中分析 Excel 大数据"
}
}]
// URL
items?
$select=id
&$expand=fields($select=id,title)
&$filter=startsWith(fields/Title, '在地图')
// Response
[{
"fields": {
"@odata.etag": "\"d72d8ed2-967f-4fd2-b198-b668477cca03,1\"",
"id": "2",
"Title": "在地图中分析 Excel 大数据"
}
}]
// URL
items?
$select=id
&$expand=fields($select=id,title)
&$filter=indexOf(fields/Title, '在地图') eq 0
// Response
{
"error": {
"code": "itemNotFound",
"message": "Item not found",
"innerError": {
"date": "2021-02-23T07:12:48",
"request-id": "a2c73b82-cac4-44b4-ae8c-3f7073ecd4f9",
"client-request-id": "6ba8a042-62b3-d067-b66f-d05258abb880"
}
}
}
any way to search the items' title using graph api would be help!使用图表 api 搜索项目标题的任何方式都会有所帮助!
update更新
I found the solution, search API could help, but got new problem.我找到了解决方案,搜索 API 可能会有所帮助,但遇到了新问题。 I post the body with lots of fields item as below.
我发布了带有很多字段项目的正文,如下所示。
// request body
{
"requests": [
{
"entityTypes": [
"listItem"
],
"query": {
"queryString": "Teams"
},
"fields": [
"id",
"VideoUrl",
"ImgUrl",
"Post",
"Category",
"SaveTime",
"title",
"created",
"Modified",
"author",
"Editor",
"ContentType"
]
}
]
}
but only got little fields of the items as below但只有很少的项目如下
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)",
"value": [
{
"searchTerms": [
"teams"
],
"hitsContainers": [
{
"total": 15,
"moreResultsAvailable": false,
"hits": [
{
"hitId": "0B94FBE2-0A2B-46EA-8AA0-B37670E4252A",
"rank": 1,
"summary": "在日常工作中...",
"resource": {
"@odata.type": "#microsoft.graph.listItem",
"id": "0B94FBE2-0A2B-46EA-8AA0-B37670E4252A",
"fields": {
"title": "利用 Teams 快速发起文档协作",
"created": "2020-09-18T09:21:42Z",
"author": "sangyak",
"contentType": "项目"
}
}
}
]
}
]
}
]
}
why only "title", "created", "author", "ContentType" included?为什么只包含“title”、“created”、“author”、“ContentType”?
Do you include the fields you want in your query?您是否在查询中包含所需的字段? I'm not sure why, but I also get a small subset of the fields when I query a list.
我不知道为什么,但是当我查询一个列表时,我也得到了一小部分字段。 I have to add the expand onto the end to get the rest of the data like:
我必须将扩展添加到末尾以获得 rest 的数据,例如:
&$select=id&$expand=fields($select=mycustomfield1,mycustomfield2,mycustomfield3,etc)
I can also simply put a wildcard in like below to see all the fields:我也可以简单地在下面放一个通配符来查看所有字段:
&$select=id&$expand=fields($select=*)
For these types of queries, I normally do not want all of the extra data on the main record, so I include that select=id
to because I only want the id field.对于这些类型的查询,我通常不想要主记录上的所有额外数据,因此我将
select=id
包括在内,因为我只想要 id 字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.