0

我正在尝试使用 SharePoint REST API更新列表项,但遇到以下错误:

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <m:code>-1, Microsoft.SharePoint.Client.InvalidClientQueryException</m:code>
    <m:message xml:lang="en-US">The expression "web/lists/GetByTitle('Drop Off Library')/items("http:/example.com/_api/Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')")" is not valid.</m:message>
</m:error>

添加文件后,我收到以下响应:

<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="http://example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
    <id>http://example.com/_api/Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')</id>
    <category term="SP.File" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" type="application/atom+xml;type=entry" title="Author" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/Author" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CheckedOutByUser" type="application/atom+xml;type=entry" title="CheckedOutByUser" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/CheckedOutByUser" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/EffectiveInformationRightsManagementSettings" type="application/atom+xml;type=entry" title="EffectiveInformationRightsManagementSettings" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/EffectiveInformationRightsManagementSettings" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/InformationRightsManagementSettings" type="application/atom+xml;type=entry" title="InformationRightsManagementSettings" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/InformationRightsManagementSettings" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ListItemAllFields" type="application/atom+xml;type=entry" title="ListItemAllFields" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/ListItemAllFields" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/LockedByUser" type="application/atom+xml;type=entry" title="LockedByUser" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/LockedByUser" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ModifiedBy" type="application/atom+xml;type=entry" title="ModifiedBy" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/ModifiedBy" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Properties" type="application/atom+xml;type=entry" title="Properties" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/Properties" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Versions" type="application/atom+xml;type=feed" title="Versions" href="Web/GetFileByServerRelativeUrl('/DropOffLibrary/b.txt')/Versions" />
    <title />
    <updated>2019-01-11T14:47:13Z</updated>
    <author>
        <name />
    </author>
    <content type="application/xml">
        <m:properties>
            <d:CheckInComment></d:CheckInComment>
            <d:CheckOutType m:type="Edm.Int32">0</d:CheckOutType>
            <d:ContentTag>{2BDD4E2D-79C8-4F6B-8DD7-AC745D9360A8},1,1</d:ContentTag>
            <d:CustomizedPageStatus m:type="Edm.Int32">0</d:CustomizedPageStatus>
            <d:ETag>"{2BDD4E2D-79C8-4F6B-8DD7-AC745D9360A8},1"</d:ETag>
            <d:Exists m:type="Edm.Boolean">true</d:Exists>
            <d:IrmEnabled m:type="Edm.Boolean">false</d:IrmEnabled>
            <d:Length m:type="Edm.Int64">4</d:Length>
            <d:Level m:type="Edm.Byte">255</d:Level>
            <d:LinkingUrl></d:LinkingUrl>
            <d:MajorVersion m:type="Edm.Int32">1</d:MajorVersion>
            <d:MinorVersion m:type="Edm.Int32">0</d:MinorVersion>
            <d:Name>b.txt</d:Name>
            <d:ServerRelativeUrl>/DropOffLibrary/b.txt</d:ServerRelativeUrl>
            <d:TimeCreated m:type="Edm.DateTime">2019-01-11T14:47:13Z</d:TimeCreated>
            <d:TimeLastModified m:type="Edm.DateTime">2019-01-11T14:47:13Z</d:TimeLastModified>
            <d:Title m:null="true" />
            <d:UIVersion m:type="Edm.Int32">512</d:UIVersion>
            <d:UIVersionLabel>1.0</d:UIVersionLabel>
            <d:UniqueId m:type="Edm.Guid">2bdd4e2d-79c8-4f6b-8dd7-ac745d9360a8</d:UniqueId>
        </m:properties>
    </content>
</entry>

我在这里的假设是,项目 id 要么是<id>标签的值,要么是标签的值<UniqueId>,但都没有奏效。

4

1 回答 1

0

首先,您应该为您的请求设置Accept标题,application/json这样结果会更好阅读。

Item ID是库中的增量整数。您可以将列添加ID到库中的视图以查看每个文件的值。由于某种原因ID,上传文件时收到的响应中缺少此内容。

要按 ID 获取项目(最佳选择),请使用:

/_api/web/lists/getByTitle('Drop Off Library')/items(1)

要通过服务器相对 url 获取项目(也是很好的选项),请使用:

/_api/web/getFileByServerRelativeUrl('/DropOffLibrary/b.txt')

UniqueId是一个不能轻易用于查询项目的 guid。您将不得不使用$filter参数,但由于性能影响,它不是最佳的。

/_api/web/lists/getByTitle('Drop Off Library')/items?$filter=GUID eq guid'2bdd4e2d-79c8-4f6b-8dd7-ac745d9360a8'
于 2019-01-11T19:20:02.063 回答