如何使用Microsoft Graph API创建SharePoint列表项?

时间:2018-06-14 07:27:47

标签: sharepoint microsoft-graph

我正在尝试使用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”:“文件和文件夹只应添加到   DocumentLibrary通过OneDrive API“

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

这里我试图在列表中创建文档的元数据。

1 个答案:

答案 0 :(得分: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"
}