【问题标题】:How to create SharePoint list item with Microsoft Graph API?如何使用 Microsoft Graph API 创建 SharePoint 列表项?
【发布时间】:2018-06-14 07:27:47
【问题描述】:

我正在尝试使用 Microsoft Graph API 为 SharePoint 端点创建列表项。我的网址如下:

https://graph.microsoft.com/v1.0/sites/{id}.sharepoint.com:/sites/{name of the site}:/lists/{list_id}/items

使用 POST 调用此 URL,以及这样的正文:

{
    "fields": {
        "FileLeafRef": "757391.pdf",
        "ContentType": "Document",
        "Application_x0020_Name": "ABC",
    }
}

它给出了错误

"message": "文件和文件夹只能添加到 通过 OneDrive API 的 DocumentLibrary"

有人可以帮忙解决这个问题吗?

我正在尝试为文档创建元数据,并在列表中。

【问题讨论】:

    标签: sharepoint microsoft-graph-api


    【解决方案1】:

    您不能像这样上传文件(即在文档库中创建 new ListItem)。您需要先使用OneDrive endpoints 上传文件:

    PUT /v1.0/sites/{site-id}/drive/items/{parent-id}:/{filename}:/content
    POST /v1.0/sites/{siteId}/drive/items/{driveItem-id}/createUploadSession
    

    在文档库中拥有文件后,您可以使用 SharePoint endpoints 更新现有文件中的元数据:

    PATCH h/v1.0/sites/{site-id}/lists/{list-id}/items/{listItem-id}/fields
    
    {
        "FileLeafRef": "757391.pdf",
        "ContentType": "Document",
        "Application_x0020_Name": "ABC"
    }
    

    【讨论】:

    • 谢谢@Marc,它正在工作。更新字段时我只面临一个问题。它正在 sharePoint 中成功更新。但是我得到这个错误的回应是:"message": "The MIME type 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2' requires a '/' character between type and subtype, such as 'text/plain'.",
    • 知道了:Accept 在添加接受后丢失,现在正在工作
    • 谢谢@Marc,它对我有用。但是,我关心的是,当我们第一次使用 PUT 请求时,如何从 OneDrive 端点检索 {listItem-id}?
    • @amzdmt 我找到了。您可以在 driveitem graph url 的末尾添加 /listItem 并发送 get 请求以获取 listitem 信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-25
    相关资源
    最近更新 更多