Get All Attachments From SharePoint List Item using Rest API and JavaScript Object Model (JSOM)

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=""></script>
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle(‘MyTestList’)/items(3)/AttachmentFiles";
url: requestUri,
type: "GET",
headers: {
"content-type": "application/json;odata=verbose",
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) {



<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.

Get All Attachments From SharePoint List Item using JavaScript Object Model (JSOM)

Now, we will discuss, how to get list item attachments using the JavaScript client object model (jsom) in SharePoint 2013/2016/Online.

Whenever a user does an attachment then the attachments are stored in an attachment folder and you can view that items attachment by URL:


Example: http://<servername>/lists/MyTestList/Attachments/1/MyTestDoc.docx

Below is the JavaScript code to get all attachments from the SharePoint list item using JavaScript.

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getWebProperties, "SP.js");
var attachmentFiles;
function getWebProperties() {
var itemId=2;
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var attachmentFolder=web.getFolderByServerRelativeUrl(‘Lists/City/Attachments/’+itemId);

attachmentFiles= attachmentFolder.get_files();
function onSuccess(sender, args) {
var i=0;
for(var file in attachmentFiles)
function onFailed(sender, args) {
alert("Something went Wrong");

Here, we discussed how to get all list item attachments using jsom (JavaScript object model) in SharePoint.

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.