---
title: "REST - Retrieve Attachment"
canonical: "https://help.agiloft.com/space/HELP/43714587/REST+-+Retrieve+Attachment"
format: markdown
---
> Macro (anchor)

The EWRetrieve operation returns an attached file from a record; <span style="color: #333333">the file is identified by its position in the field, in case multiple files are attached, and the URL must specify the record ID, the name of the field, and the position of the file to be retrieved.</span> 

- **Returns**: the file content in the body of the response, using a GET or POST HTTP method.
- **Supported Content-Type**<span style="color: #333333">: the Content-Type used when attaching the original file.</span>
- Accepts a URL with URL-encoded parameters and record data. For more information about general URL conventions, see [REST Interface](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

## JavaScript Example

Here is an example of a JavaScript-based client that invokes the REST interface via AJAX: 

```javascript
     function xmlhttpGet (strURL) {
        var xmlHttpReq=false;
        var self=this;
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            try {
                netscape.security.PrivilegeManager.
                  enablePrivilege("UniversalBrowserRead");
            } catch (e) {
                alert("Permission UniversalBrowserRead denied.");
            }
            self.xmlHttpReq=new XMLHttpRequest();
        }// IE
        else if (window.ActiveXObject) {
            self.xmlHttpReq=new ActiveXObject("Microsoft.xmlHTTP");
        }
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.onreadystatechange=requestComplete;
        self.xmlHttpReq.send(null);
    }
    function requestComplete() {
        if (xmlHttpReq.readyState==4||xmlHttpReq.readyState=="complete") {
            alert ("A file has been returned");
        }
    }
    function main() {
        xmlhttpGet('https://localhost:8080/ewws/EWRetrieve?$KB=Demo&$table=someTable&$login=admin&$password=qwerty&id=1234&field=someField&filePosition=1#39;
    }
```

# Error Codes

These error codes are for EWRetrieve only, but are not an extensive list of possible error codes. For any errors not listed here, consult the General Error Codes section of [https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

|  |  |  |  |
| --- | --- | --- | --- |
| Scenario | Type | Code | Description |
| No data found for the provided request | VALIDATION | 400 | EWWrongDataException → Search in table <tableName>   by primary field <primaryKeyName> returns no records for key   <recordId> |

> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)