0

I am trying to query the ServerRelativeUrl to get the list item attachment. Below is the xml. d/results(0)/ServerRelativeUrl always returns empty. I can query the Id properly with d/results(0)/Id just can't get the filename or url.

<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://bsktoday/depts/accounting/_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>c00374cf-6d42-462b-89ed-f3fba5204961</id>
<title />
<updated>2018-07-06T19:19:40Z</updated>
<entry m:etag="&quot;2&quot;">
    <id>af5554dd-4332-4374-adaf-0cc41fd67c62</id>
    <category term="SP.Data.Work_x0020_In_x0020_ProcessListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" href="Web/Lists(guid'c194f5c3-1759-4df5-baa1-ae45237d2589')/Items(53)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'c194f5c3-1759-4df5-baa1-ae45237d2589')/Items(53)/AttachmentFiles">
        <m:inline>
            <feed>
                <id>1509e208-782e-41a4-bb13-ad724cdb90dd</id>
                <title />
                <updated>2018-07-06T19:19:40Z</updated>
                <entry>
                    <id>http://bsktoday/depts/accounting/_api/Web/Lists(guid'c194f5c3-1759-4df5-baa1-ae45237d2589')/Items(53)/AttachmentFiles('testing1.csv')</id>
                    <category term="SP.Attachment" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
                    <link rel="edit" href="Web/Lists(guid'c194f5c3-1759-4df5-baa1-ae45237d2589')/Items(53)/AttachmentFiles('testing1.csv')" />
                    <title />
                    <updated>2018-07-06T19:19:40Z</updated>
                    <author>
                        <name />
                    </author>
                    <content type="application/xml">
                        <m:properties>
                            <d:ServerRelativeUrl>/depts/accounting/Lists/Work In Process/Attachments/53/testing1.csv</d:ServerRelativeUrl>
                        </m:properties>
                    </content>
                </entry>
            </feed>
        </m:inline>
    </link>
    <title />
    <updated>2018-07-06T19:19:40Z</updated>
    <author>
        <name />
    </author>
    <content type="application/xml">
        <m:properties>
            <d:Id m:type="Edm.Int32">53</d:Id>
            <d:ID m:type="Edm.Int32">53</d:ID>
            <d:Attachments m:type="Edm.Boolean">true</d:Attachments>
        </m:properties>
    </content>
</entry>

2 Answers 2

0

If that is the XML returned, then you will probably need something like this:

d/results(0)/feed/entry/link(1)/inline/feed/entry/content/properties/ServerRelativeUrl

If you are returning JSON, the format is a bit simpler:

yourJavaScriptObject.d.ServerRelativeUrl
0

Thanks for the suggestion but the answer I figured out was a slightly different query to the API.

/_api/web/lists/getbytitle('list name here')/items(item id here)/AttachmentFiles

then return d/results(0)/serverrelativeurl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.