Использование API REST SharePoint для обновления элемента списка - PullRequest
0 голосов
/ 11 января 2019

Я пытаюсь обновить элемент списка с помощью API REST SharePoint, но у меня возникает следующая ошибка:

<?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>, либо значением тега <UniqueId>, но ни один из них не сработал.

1 Ответ

0 голосов
/ 11 января 2019

Сначала вы должны установить заголовок 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 - это гид, который не может быть легко использован для запроса элемента. Вам придется использовать параметр $filter, но он не оптимален из-за влияния на производительность.

/_api/web/lists/getByTitle('Drop Off Library')/items?$filter=GUID eq guid'2bdd4e2d-79c8-4f6b-8dd7-ac745d9360a8'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...