API – Downloading Customer Documents

Introduction

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.

When you pull document information through the API, you'll notice the active property for all documents will be 1—even for documents that have been inactivated. If a document is inactivated, its active status will remain the same, and its archived status will change to a value of 1.

Finding the Document

To download a customer document, you will first need to identify which customer document you wish to download. This is done by querying the associated customer 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:

GET https://loanpro.simnang.com/api/public/api/1/odata.svc/Customers(<id>)?$expand=Documents,Documents/
FileAttachment&nopaging=true

The <id> is the ID of the associated customer. This means that if we want to get the list of customer documents for customer #2, we would send the GET request

GET https://loanpro.simnang.com/api/public/api/1/odata.svc/Customers(2)?$expand=Documents,Documents/FileAttachment&nopaging=true

The response would look similar to the following:

{
"d": {
"__metadata": {
"uri": "https://loanpro.simnang.com/api/public/api/1/odata.svc/Customers(id=2)",
"type": "Entity.Customer"
},
"PrimaryAddress": {
"__deferred": {
"uri": "Customers(id=2)/PrimaryAddress"
}
},
"MailAddress": {
"__deferred": {
"uri": "Customers(id=2)/MailAddress"
}
},
"Employer": {
"__deferred": {
"uri": "Customers(id=2)/Employer"
}
},
"References": {
"__deferred": {
"uri": "Customers(id=2)/References"
}
},
"PaymentAccounts": {
"__deferred": {
"uri": "Customers(id=2)/PaymentAccounts"
}
},
"Phones": {
"__deferred": {
"uri": "Customers(id=2)/Phones"
}
},
"CustomFieldValues": {
"__deferred": {
"uri": "Customers(id=2)/CustomFieldValues"
}
},
"Documents": [
{
"__metadata": {
"uri": "https://loanpro.simnang.com/api/public/api/1/odata.svc/CustomerDocuments(id=1)",
"type": "Entity.CustomerDocument"
},
"Customer": {
"__deferred": {
"uri": "CustomerDocuments(id=1)/Customer"
}
},
"DocSection": {
"__deferred": {
"uri": "CustomerDocuments(id=1)/DocSection"
}
},
"FileAttachment": {
"__metadata": {
"uri": "https://loanpro.simnang.com/api/public/api/1/odata.svc/FileAttachments(id=6)",
"type": "Entity.FileAttachment"
},
"id": 6,
"parentType": "Entity.CustomerDocument",
"parentId": 1,
"fileName": "res_1494258197.txt",
"fileOriginalName": "res.txt",
"fileSize": 16,
"fileMime": "text/plain"
},
"id": 1,
"fileName": "res.txt",
"description": null,
"sectionId": 1,
"userId": 806,
"userName": "Simnang Support",
"remoteAddress": "73.98.150.163, 10.0.",
"size": 16,
"archived": 0,
"active": 1,
"created": "/Date(1494258197)/"
}
],
"CreditScore": {
"__deferred": {
"uri": "Customers(id=2)/CreditScore"
}
},
"Loans": {
"__deferred": {
"uri": "Customers(id=2)/Loans"
}
},
"SocialProfiles": {
"__deferred": {
"uri": "Customers(id=2)/SocialProfiles"
}
},
"Notes": {
"__deferred": {
"uri": "Customers(id=2)/Notes"
}
},
"id": 2,
"customId": null,
"mcId": 87350,
"customerType": "customer.type.individual",
"status": "Active",
"firstName": "John",
"lastName": "Doe",
"middleName": null,
"birthDate": "/Date(0)/",
"gender": "customer.gender.male",
"generationCode": "customer.generationCode.none",
"email": "john.doe@email.com",
"ssn": "000000000",
"driverLicense": "123-45-6789",
"companyName": null,
"contactName": null,
"customerIdType": "customer.idType.ssn",
"customerId": null,
"creditLimit": 0,
"accessUserName": "john.doe0000",
"accessPassword": null,
"active": 1,
"ofacMatch": 0,
"ofacTested": 0,
"hasAvatar": 0,
"loanRole": null,
"created": "/Date(1493234716)/",
"lastUpdate": "/Date(1493924207)/",
"creditScoreId": null
}
}

There are two fields of interest in each results object. The first is the “id” field; this is the ID of the CustomerDocument 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:

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

Where <tenant_id> is your tenant’s ID, <id> is the ID of the customer document, and <filename> is the filename of the customer document. For this article, we’ll use the tenant id of 5200243, and we’ll use the customer document id and filename used in the above section, which is 47 and customer_document_6217a94d247adf032a3f8fb64e79cf1c12f7a59f2681f.txt respectively.

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

GET https://loanpro.simnang.com/api/public/api/1/files/5200243/CustomerDocuments(47)/customer_document_6217a94d247adf032a3f8fb64e79cf1c12f7a59f2681f.txt
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.


How did we do?


Powered by HelpDocs (opens in a new tab)