简体   繁体   English

Microsoft graph Api 获取 sharepoint 列表项,使用查询 $filter=indexOf 或 $search 未找到项

[英]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。

I Have been Succeeded in Getting the List Items我已成功获取列表项

  • Here is the URL I use and the query without using $filter这是我使用的 URL 和不使用 $filter 的查询
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 大数据"
            }
        }]
  • When I add the $filter=startsWith(fields, '在地图'), it still work当我添加 $filter=startsWith(fields, '在地图') 时,它仍然有效
// 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 大数据"
      }
   }]

Then I Got Stuck然后我卡住了

// 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"
        }
    }
}
  • Then I tried to use $search instead, but just receive the whole list items, it didn't work too然后我尝试改用 $search ,但只接收整个列表项,它也没有用

Does anyone figure out Any Way to Resolve the Problem?有没有人想出解决问题的任何方法?

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.

相关问题 Microsoft Graph API 过滤器 SharePoint 按用户创建的列表项 - Microsoft Graph API Filter SharePoint List Items By CreatedBy User 如何在 Microsoft Graph API 中使用过滤器来获取 SharePoint 项目? - How to use filter in Microsoft Graph API to get SharePoint items? 使用Microsoft Data Flow通过OData筛选器查询从Sharepoint列表中获取过期日期的未清项目 - Using OData Filter Query to get open items with past due date from Sharepoint list using Microsoft Flow 如何使用 postman 调用 MS Graph Search API 获取 SharePoint 列表项 - how to call MS Graph Search API for get SharePoint list items using postman Microsoft Graph API - Sharepoint 列表无法调用创建/更新 SharePoint 列表项,GET/DELETE 有效 - Microsoft Graph API - Sharepoint list unable to call create/update SharePoint list items, GET/DELETE works 使用Graph API查询SharePoint列表项并扩展用户字段 - Using Graph API to query SharePoint list items and expand user field 如何筛选使用 Microsoft Graph 查询的 Sharepoint 列表项 - How to filter Sharepoint List Items Queried with Microsoft Graph 如何在 Microsoft Graph 中按创建者过滤 SharePoint 列表项? - How to filter SharePoint list items by Created by in Microsoft Graph? Microsoft Graph API SharePoint搜索 - Microsoft Graph API SharePoint search Microsoft Graph API:SharePoint:在“根站点”的“默认驱动器”中获取项目列表 - Microsoft Graph API: SharePoint: Get items list in "default Drive" of "root Site"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM