如何使用Microsoft Graph API中的筛选器获取SharePoint项目?

时间:2018-06-19 14:28:37

标签: sharepoint microsoft-graph sharepoint-online boomi

在这里,我尝试根据创建的日期过滤数据。一开始,我在Graph Explorer中尝试过,并且可以正常工作。

https://graph.microsoft.com/v1.0/me/messages?$filter=createdDateTime ge 2017-09-04&$select=subject,lastModifiedDateTime

现在尝试在Dell Boomi中实现相同功能。这是提取所有项目的资源路径:sites/{id}.sharepoint.com:/sites/{id}:/lists/{list_id}/items 一切正常。

之后,我要添加过滤条件:

sites/{id}.sharepoint.com:/sites/{id}:/lists/{list_id}/items?$filter=lastModifiedDateTime ge 2017-09-04&$select=email,displayName

这里出现错误。这是错误消息:

<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request</h2>
<hr><p>HTTP Error 400. The request is badly formed.</p>

请问对此有何帮助,如何解决此问题? 这是示例数据。

> {   "@odata.context":
> "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)(&#39;1334af71-5b7a-4276-a8d8-c3f3f129051d&#39;)/items",
> "value": [
>     {
>       "@odata.etag": "&quot;ef6e961c-a956-400e-a77d-f044d2e0b894,8&quot;",
>       "createdDateTime": "2018-05-24T13:38:10Z",
>       "eTag": "&quot;ef6e961c-a956-400e-a77d-f044d2e0b894,8&quot;",
>       "id": "3",
>       "lastModifiedDateTime": "2018-06-18T10:24:27Z",
>       "webUrl": "https://{id}.sharepoint.com/sites/{id}/Doc%20Interfaces/757391.pdf",
>       "createdBy": {
>         "user": {
>           "email": "abc@abc.COM",
>           "id": "173abc",
>           "displayName": "abc"
>         }
>       },
>       "lastModifiedBy": {
>         "user": {
>           "email": "xyz@abc.COM",
>           "id": "234xyz",
>           "displayName": "xyz"
>         }
>       },
>       "parentReference": {
>         "id": "03fe-16595a0da875"
>       },
>       "contentType": {
>         "id": "0x01"
>       },
>       "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)(&#39;1334f71-c3f3f129&#39;)/items(&#39;3&#39;)/fields/$entity",
>       "fields": {
>         "@odata.etag": "&quot;ef6e961-f044d2e0b894,8&quot;",
>         "FileLeafRef": "757391.pdf",

3 个答案:

答案 0 :(得分:3)

简短回答

使用自动生成的SharePoint列表项字段已创建已修改

/items?expand=fields&$filter=fields/Modified gt '2018-01-01'

重要提示

要在这些字段上执行过滤器查询,您将必须:

  • 为这些列编制索引(请参见here的方式)
  • 或在您的请求上设置'Prefer:HonorNonIndexedQueriesWarningMayFailRandomly'标头(Microsoft不建议)

奖励

似乎不支持对图端点返回的值(例如lastModifiedDateTime,createdDateTime等)进行过滤,因为请求 / items&$ filter = lastModifiedDateTime ge'2018-01-01 '将返回“无效的过滤子句” 错误。

答案 1 :(得分:0)

请尝试

sites/{id}.sharepoint.com:/sites/{id}:/lists/{list_id}/items?$filter=lastModifiedDateTime ge '2017-09-04'&$select=email,displayName

filter=lastModifiedDateTime ge '2017-09-04'->单引号

注意:如果您选择任何查找值,则需要使用$expand查询选项  例如:

sites/{id}.sharepoint.com:/sites/{id}:/lists/{list_id}/items?$filter=lastModifiedDateTime ge '2017-09-04'&$select=email,displayName&$expand=displayName/Name

答案 2 :(得分:0)

在向Boomi提交OData查询时,我解决了一个非常类似的问题。问题是过滤器字符串中的空格:

您的字符串:$ filter = lastModifiedDateTime ge'2017-09-04' 应该是:$ filter = lastModifiedDateTime%20ge%20'2017-09-04'