Get All Attachments From SharePoint 2013 List Item using Rest API

Get All Attachments From SharePoint 2013 List Item using Rest API
SharePoint deveopment training course

This SharePoint Rest API tutorial 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 in SharePoint 2013/Online.

If you are new to Rest API, then check SharePoint Rest API Tutorial and Examples.

Get All Attachments From SharePoint 2013 List Item using Rest API

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

Put the below code in a script editor web part or inside a content 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"/>

Once you save the code and click on the button, it will display all the attachments in the alert dialog box in SharePoint Online or SharePoint 2013/2016.

You may like following SharePoint Rest API tutorials:

You may also like following SharePoint Rest API tutorials:

Hope this SharePoint tutorial helps to get all attachments from a SharePoint list item using Rest API.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

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 →