首页 > 解决方案 > 如何使用 API 从 SharePoint 中的列表下载附件?

问题描述

如何使用 Python 中的 API 从 SharePoint 中的列表(而不是页面的文档)下载附件?

我有一个包含 60 多行的列表,内容是从 Power App 表单添加的。每行是一个不同的条目,可能有也可能没有附件。

我正在开发一个自动化流程,该流程将读取列表的每一行并将其输入 SAP。我似乎找不到可以从列表中获取附件的 API,它们都是关于从页面的文档文件夹中获取它们。

下面是我正在使用的站点 URL,以及列表的样子。

https://{site url}/sites/{group name}/Lists/{listname}/AllItems.aspx?e=3%3A32b71e288cd841f5b13422c0b99ffe89&at=9

在此处输入图像描述

标签: pythonrestsharepointautomation

解决方案


function GetListItemAttachments() {
// Specify the Id of the Item that you want to fetch
var Itemid = 1;

$.ajax
({
    // _spPageContextInfo.webAbsoluteUrl - will give absolute URL of the site where you are running the code.
    // You can replace this with other site URL where you want to apply the function

    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('List Name')/items(" + Itemid + ")/AttachmentFiles",
    method: "GET",
    headers:
       {
           // Accept header: Specifies the format for response data from the server.
           "Accept": "application/json;odata=verbose"
       },
    success: function (data, status, xhr) {
        var dataresults = data.d.results;
        for (var i = 0; i < dataresults.length; i++) {
            alert(dataresults[i]["FileName"]);
        }
    },
    error: function (xhr, status, error) {
        console.log("Failed");
    }
});
}

阅读更多:使用 REST API 从 SharePoint 中的列表项中获取所有附件


推荐阅读