You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Microsoft Graph API获取SharePoint中最新指定前缀CSV文件

解决SharePoint Graph API获取最新文件的问题

原请求的问题分析

你的请求未实现排序,核心原因有两个:

  1. URL路径错误:错误将文档库名称Shared Documents嵌套进站点路径,正确结构需先指定站点,再关联对应的列表/文档库。
  2. OData参数格式错误:orderby缺少$前缀,Graph API的OData查询参数(如$orderby、$filter)必须以$开头,否则无法被识别。

修正后的List Items API请求

使用List Items API可精准获取所需字段并仅返回最新文件:

GET https://graph.microsoft.com/v1.0/sites/company.sharepoint.com/sites/{你的站点名称}/lists/{列表ID}/items?$select=webUrl&$expand=fields($select=LinkFilename,Datatype,Modified)&$filter=startswith(LinkFilename,'ABC_')&$orderby=Modified desc&$top=1

参数说明:

  • $select=webUrl:直接获取文件的网页访问地址
  • $expand=fields(...):展开自定义字段集合,筛选出LinkFilename、Datatype和Modified
  • $filter=startswith(LinkFilename,'ABC_'):过滤文件名以ABC_开头的文件
  • $orderby=Modified desc:按修改时间降序排序,确保最新文件排在首位
  • $top=1:仅返回排序后的第一条数据(即最新文件)

替代方案:使用Drive API

文档库本质是SharePoint的Drive,用Drive API操作文件更直观,也能获取自定义字段:

GET https://graph.microsoft.com/v1.0/sites/company.sharepoint.com/sites/{你的站点名称}/drive/root/children?$select=name,webUrl,lastModifiedDateTime&$expand=listItem($select=fields/Datatype)&$filter=startswith(name,'ABC_')&$orderby=lastModifiedDateTime desc&$top=1

参数说明:

  • name对应List Items中的LinkFilename,lastModifiedDateTime对应Modified
  • $expand=listItem(...):关联文件对应的列表项,获取自定义的Datatype字段
  • 其余参数作用与List Items API一致,实现筛选、排序并获取最新文件

内容的提问来源于stack exchange,提问作者Data Rish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 15:58:15