Office 365 SharePoint 2013 Online Retreive The Attachment Files From List Item Using REST API

To use the example in this blog, you'll need

A SharePoint 2013 development environment (app isolation required for On-Premises scenario).

Visual Studio 2012 or Visual Studio 2013 with Office Developer Tools for Visual Studio 2012, or Napa (SharePoint Online only).

You'll also need to set full control add-in permissions at the Web scope. Only the users who have sufficient permissions to change the list permissions (such as site owners) can run this add-in. 
  1. <script>  
  2. var siteUrl = 'http://gowthamr.SharePoint.com';  
  3. var listTitle = 'Tutorial List';  
  4. var itemid='5';  
  5. $(document).ready( function() {  
  6.     getattachmentfiles();  
  7. });  
  8.   
  9.   
  10. function getattachmentfiles() {  
  11.     $.ajax({  
  12.        url: siteUrl+"/_api/web/lists/GetByTitle("+listTitle+")/items(itemid)/AttachmentFiles('file name')/"  
  13.         method: GET,  
  14.         headers:{  
  15.         Authorization: "Bearer " + accessToken  
  16.         accept: "application/json;odata=verbose",  
  17.             content-type: "application/json;odata=verbose"  
  18.             content-length:length of post body},  
  19.              success: successHandler(responseData),                 
  20.         error: errorHandler  
  21.        });  
  22. }  
  23. function successHandler(responseData) {  
  24.             var attachments=responseData.d.results;  
  25.     alert('Request updated Successfully.');  
  26. }   
  27.   
  28. function errorHandler(xhr, ajaxOptions, thrownError) {  
  29.     alert('Request failed: ' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);  
  30. }  
  31. </script>   
Conclusion

Was my blog helpful?

If so, please let me know at the bottom of this page. If not, let me know what was confusing or missing and I will use your feedback to double-check the facts, add info and update this blog.
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now