首页 > 解决方案 > Office365 REST API 查询添加超链接到列表?ClientServiceException 无法反序列化 Microsoft.SharePoint.SPFieldUrlValue 类型的数据

问题描述

我正在使用官方 Office 365 REST API 从列表中检索项目并将文件上传到 Sharepoint 和 Onedrive https://github.com/vgrem/Office365-REST-Python-Client/blob/master/examples/sharepoint/ listitem_operations.py

我目前正在尝试找到一种将附件包含到我的 Sharepoint 列表中的方法,而我正在尝试做的是将 Web URL 插入到我的列表中。但是,因为它是超链接类型,所以我收到一个异常错误提示Cannot deserialize data for type Microsoft.SharePoint.SPFieldUrlValue.', "500 Server Error: Internal Server Error for url:

我知道对于直接查询,它必须看起来像:

'__metadata': {'type': 'SP.Data.TasksListItem'},
{Url: 'http://google.com', Description: 'This is the description'}

有什么方法可以更正确地格式化 API 查询,以便我可以正确上传链接?或者有没有办法将项目作为文本上传,并在 Sharepoint 中显示为可点击的超链接?

编辑:只是为了澄清,这是用于更新列表项的功能:

def update_list_item(lst, row_id, column, value):
    print("Update list item example...")
    list_object = ctx.web.lists.get_by_title(lst)
    item_id = str(row_id)
    item = list_object.get_item_by_id(item_id)
    item.set_property(column, str(value))
    item.set_property('Key', 'Value')
    item.update()
    ctx.execute_query()
    print("List item '{0}' has been updated.".format(item_id))

标签: c#pythonrestsharepointoffice365

解决方案


尝试使用这个:

    '__metadata': { 'type': 'SP.Data.TasksListItem' },
    'Field': 
            {
                '__metadata': { 'type': 'SP.FieldUrlValue' },
                'Description': 'This is the description',
                'Url': 'http://google.com'
            }

推荐阅读