Get All Attachments From SharePoint 2013 List Item using Rest API

InfoPath alternatives for form designing SharePoint

Here we will discuss how we can retrieve all attachments from a SharePoint 2013 list item using Rest API in SharePoint 2013. Here I have a list and each item has some attachments. We will try to retrieve all the attachments from a particular item using Rest API.

You may read:
– Add user to SharePoint group using JavaScript object model in SharePoint 2013

– Get SharePoint 2013 List Item Count using Rest API and ECMAScript object model

– Record Management in SharePoint 2013 or SharePoint 2013 Online

In this example I am trying to retrieve attachments from item whose id is 3.

Put the below code in a script editor web part.

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
<script>
$(function(){
$(“#btnClick”).click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getbytitle(‘MyTestList’)/items(3)/AttachmentFiles”;
$.ajax({
url: requestUri,
type: “GET”,
headers: {
“accept”:”application/json;odata=verbose”,
“content-type”: “application/json;odata=verbose”,
“X-RequestDigest”:$(“#_REQUESTDIGEST”).val()
},
success: onSuccess,
error: onError
});

function onSuccess(data) {
var itemsCount = data.d.results.length;
alert (itemsCount);
if (data) {
$.each(data.d.results, function () {
// do something
alert( this.ServerRelativeUrl);
});
}
}

function onError(error) {

alert(JSON.stringify(error));

}

});

});

</script>

<input type=”button” id=”btnClick” value=”Get Attachments”/>

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply