# API – Downloading Loan Documents

### General

This article covers how to download the contents of an uploaded document. To learn about how to upload, update, or create documents please see the article API – Documents.

Note: When you pull document information through the API the active property will show 0 for active documents. That is because this property is being used to show whether a document has been archived, so 0 means it has not been archived and is therefore active.

#### Finding the Document

To download a loan document, you will first need to identify which loan document you wish to download. This is done by querying the associated loan for its documents while expanding the associated FileAttachment entity (see API – Expanding objects for more information). This is done by sending the following GET request:

https://loanpro.simnang.com/api/public/api/1/odata.svc/Loans(<id>)/Documents?all&$expand=FileAttachment Where <id> is the ID of the associated loan. This means that if we want to get the list of loan documents for loan #4, we would send the GET request https://loanpro.simnang.com/api/public/api/1/odata.svc/Loans(4)/Documents?all&$expand=FileAttachment

The response would look similar to the following:

{
"d": {
"results": [
{
"__metadata": {
"uri": "http://loanpro.simnang.com/api/public/api/1/odata.svc/LoanDocuments(id=1)",
"type": "Entity.Document"
},
"Loan": {
"__deferred": {
"uri": "LoanDocuments(id=1)/Loan"
}
},
"User": {
"__deferred": {
"uri": "LoanDocuments(id=1)/User"
}
},
"DocSection": {
"__deferred": {
"uri": "LoanDocuments(id=1)/DocSection"
}
},
"FileAttachment": {
"__metadata": {
"uri": "http://loanpro.simnang.com/api/public/api/1/odata.svc/FileAttachments(id=451)",
"type": "Entity.FileAttachment"
},
"id": 451,
"parentType": "Entity.LoanDocument",
"parentId": 418,
"fileName": "API_Help_1474483773.pdf",
"fileOriginalName": "API Help",
"fileSize": 11386,
"fileMime": "application/octet-stream"
},
"id": 418,
"loanId": 4,
"userId": 5,
"sectionId": 3,
"fileAttachmentId": 451,
"userName": "API Helpsystem",
"remoteAddress": "255.255.255.255",
"fileName": "API Help",
"description": null,
"ip": 0,
"size": 11386,
"active": 1,
"created": "/Date(1474483773)/",
"archived": 0,
"customerVisible": 0
}
],
"summary": {
"start": 0,
"pageSize": 1,
"total": 1
}
}
}

There are two fields of interest in each results object. The first is the “id” field; this is the ID of the LoanDocument entity. The other is the “fileName” of the nested fileAttachment object. We will need both of these fields to download the document. In this case, the id is 418 and the file name is API_Help_1474483773.pdf.

#### Downloading the document

Once you have the “id” and “fileName” field values, you will be able to download the document. This is done by sending another GET request. The URL for the GET request will be formatted as follows:

https://loanpro.simnang.com/api/public/api/1/files/<tenant_id>/LoanDocuments(<id>)/<filename>

Where <tenant_id> is your tenant’s ID, <id> is the ID of the loan document, and <filename> is the filename of the loan document. For this article, we’ll use the tenant id of 0, and we’ll use the loan document id and filename used in the above section, which is 418 and API_Help_1474483773.pdf respectively.

With those variables set, our final GET request will be:

https://loanpro.simnang.com/api/public/api/1/files/0/LoanDocuments(418)/API_Help_1474483773.pdf

Please note that the response will be in binary. This is because the request will be sending the raw file data. Please make sure you receive, process, and store the data appropriately.