API – Downloading Customer 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 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:

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

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

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:

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 0, and we’ll use the customer document id and filename used in the above section, which is 1 and res_1494258197.txt respectively.

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

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