【问题标题】:Uppload data from JSON to Sharepoint List with Microsoft Graph API in Python使用 Python 中的 Microsoft Graph API 将数据从 JSON 上传到 Sharepoint 列表
【发布时间】:2021-05-05 09:06:34
【问题描述】:

我正在尝试从与目标 SharePoint 列表具有相同结构的 JSON 文件中添加一些数据。我之前检查过我是否可以使用 get 方法访问该列表,并且我可以进行身份​​验证并获取令牌。问题是我似乎无法弄清楚如何正确上传数据。

下面是我的简化代码

URL= 'https://graph.microsoft.com/vx.x/sites/sharepointname/sites/group/lists/listId/rows/add'
json_file = a pandas file converted to json

post_data = requests.post( URL,
            headers={'Authorization': 'Bearer ' + token['access_token'], 'Content-Type': 'application/json'},
            data = json_file
            )

这不起作用,我得到的一些错误是“找不到段 \uxxrows\uxxx 的资源”。 如果有任何帮助,我将不胜感激。

【问题讨论】:

    标签: python flask sharepoint microsoft-graph-api microsoft-graph-files


    【解决方案1】:

    我认为您可能弄错了网址。这可以解释您遇到的 Resource not found for the segment... 错误。

    如果您尝试创建新列表,here's the documentation
    网址 - POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists

    如果您尝试将项目添加到现有列表中,here's the documentation
    网址 - POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items

    【讨论】:

    • 我终于解决了。 URL 确实是错误的,正确的是URL='https://graph.microsoft.com/vxx/sites/sharepointsite:/sites/site:/lists/list id/items'。另外,我上传 JSON 的方式是错误的。要生成有效的 JSON,我必须从 panda 数据帧中单独获取每一行,将其转换为适当的格式,然后按以下方式对每一行执行 POST 操作:requests.post( URL, headers={'Authorization': 'Bearer ' + token['access_token'] , 'content-type': 'application/json'}, json=data, ) 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2021-04-07
    • 2017-10-09
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2022-01-19
    • 1970-01-01
    相关资源
    最近更新 更多