Skip to main content

BPMCore Documents API

The Documents API enables uploading, storing, and retrieving documents attached to various banking entities such as clients, loans, deposits, and insurance policies. Files are stored in MinIO object storage with metadata tracked in the database.

Base Endpoint

POST /api/core/cmd

Commands & Queries

1. Create Document (Upload)

Uploads a document and attaches it to a specific banking entity.

Command Name: CreateDocumentCommand

Request Parameters

ParameterTypeRequiredDescription
entityTypestringYesEntity type: "Client", "Loan", "Deposit", or "Policy"
entityIdlongYesID of the entity (clientId, loanId, depositId, or policyId)
fileNamestringYesOriginal file name with extension
fileContentBase64stringYesBase64-encoded file content
titlestringNoDocument title
descriptionstringNoDocument description
documentNumberstringNoDocument number (e.g., ID card number)
documentTypeintegerNoDocument type enum value
documentTypeDescriptionstringNoDocument type description
issueDatestringNoDocument issue date (YYYY-MM-DD)
expiryDatestringNoDocument expiry date (YYYY-MM-DD)

Document Types (Examples)

ValueDescription
1National ID
2Passport
3Driver's License
4Utility Bill
5Bank Statement
6Contract
7Other

Request Example

{
"Cmd": "CreateDocumentCommand",
"Data": {
"entityType": "Client",
"clientId": 12345,
"fileName": "passport.pdf",
"fileContentBase64": "JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYX...",
"title": "International Passport",
"description": "Valid passport for KYC verification",
"documentNumber": "A12345678",
"documentType": 2,
"documentTypeDescription": "Passport",
"issueDate": "2020-01-15",
"expiryDate": "2030-01-14"
}
}

Response Structure

{
"IsSuccessful": true,
"StatusCode": "00",
"Message": "Document uploaded successfully.",
"Data": {
"Identifier": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"FilePath": "documents/clients/12345/passport_3fa85f64.pdf",
"FileExtension": ".pdf",
"OriginalFileName": "passport.pdf",
"UploadedAt": "2024-01-20T14:30:00",
"UploadedBy": "admin@banklingo.com",
"StorageProvider": "MinIO"
}
}

Validation Rules

  1. Entity Must Exist: The specified entity ID must exist in the system
  2. Valid Base64: File content must be valid base64-encoded string
  3. File Size: Maximum file size limits apply (configured in system settings)
  4. Supported Formats: PDF, PNG, JPG, JPEG, DOC, DOCX, XLS, XLSX typically supported
  5. Unique Document Number: Optional but should be unique if provided

Error Responses

{
"IsSuccessful": false,
"StatusCode": "01",
"Message": "Invalid client ID.",
"Data": null
}
{
"IsSuccessful": false,
"StatusCode": "01",
"Message": "Invalid file content.",
"Data": null
}

2. Retrieve Documents List (All Entities)

Retrieves a paginated list of all documents across all entity types.

Command Name: RetrieveDocumentsListQuery

Request Parameters

ParameterTypeRequiredDescription
entityTypestringNoFilter by entity type: "Client", "Loan", "Deposit", "Policy"
entityIdlongNoFilter by specific entity ID
startDatestringNoFilter by upload date start (YYYY-MM-DD)
endDatestringNoFilter by upload date end (YYYY-MM-DD)
searchTextstringNoSearch in file names, titles, descriptions
documentTypeintegerNoFilter by document type
pageNumberintegerNoPage number (default: 1)
pageSizeintegerNoItems per page (default: 20)
isExportbooleanNoExport all results (default: false)

Request Example

{
"Cmd": "RetrieveDocumentsListQuery",
"Data": {
"entityType": "Client",
"startDate": "2024-01-01",
"endDate": "2024-01-31",
"searchText": "passport",
"pageNumber": 1,
"pageSize": 50
}
}

Response Structure

{
"IsSuccessful": true,
"StatusCode": "00",
"Message": "Documents retrieved successfully.",
"Data": {
"items": [
{
"Id": 789,
"EntityType": "Client",
"EntityId": 12345,
"EntityReference": "CL-000123",
"FileName": "passport.pdf",
"FilePath": "documents/clients/12345/passport_3fa85f64.pdf",
"FileExtension": ".pdf",
"Title": "International Passport",
"Description": "Valid passport for KYC verification",
"DocumentNumber": "A12345678",
"DocumentType": 2,
"DocumentTypeDescription": "Passport",
"IssueDate": "2020-01-15",
"ExpiryDate": "2030-01-14",
"UploadedAt": "2024-01-20T14:30:00",
"UploadedBy": "admin@banklingo.com",
"FileSize": "245760",
"IsExpired": false
}
],
"totalRows": 125,
"totalPages": 3,
"pageSize": 50,
"currentPage": 1
},
"HasNext": true,
"HasPrevious": false
}

3. Retrieve Client Documents

Retrieves all documents for a specific client.

Command Name: RetrieveClientDocumentsListQuery

Request Parameters

ParameterTypeRequiredDescription
clientIdlongYesClient ID
documentTypeintegerNoFilter by document type
pageNumberintegerNoPage number (default: 1)
pageSizeintegerNoItems per page (default: 20)
isExportbooleanNoExport all results (default: false)

Request Example

{
"Cmd": "RetrieveClientDocumentsListQuery",
"Data": {
"clientId": 12345,
"pageNumber": 1,
"pageSize": 20
}
}

Response Structure

Same structure as RetrieveDocumentsListQuery, filtered to the specified client.


4. Retrieve Loan Documents

Retrieves all documents for a specific loan account.

Command Name: RetrieveLoanDocumentsListQuery

Request Parameters

ParameterTypeRequiredDescription
loanIdlongYesLoan account ID
documentTypeintegerNoFilter by document type
pageNumberintegerNoPage number (default: 1)
pageSizeintegerNoItems per page (default: 20)
isExportbooleanNoExport all results (default: false)

Request Example

{
"Cmd": "RetrieveLoanDocumentsListQuery",
"Data": {
"loanId": 67890,
"pageNumber": 1,
"pageSize": 20
}
}

Typical Loan Documents

  • Loan application form
  • Collateral documents
  • Property valuations
  • Guarantor documents
  • Signed loan agreement
  • Disbursement authorization

5. Retrieve Deposit Documents

Retrieves all documents for a specific deposit account.

Command Name: RetrieveDepositDocumentsListQuery

Request Parameters

ParameterTypeRequiredDescription
depositIdlongYesDeposit account ID
documentTypeintegerNoFilter by document type
pageNumberintegerNoPage number (default: 1)
pageSizeintegerNoItems per page (default: 20)
isExportbooleanNoExport all results (default: false)

Request Example

{
"Cmd": "RetrieveDepositDocumentsListQuery",
"Data": {
"depositId": 54321,
"pageNumber": 1,
"pageSize": 20
}
}

Typical Deposit Documents

  • Account opening form
  • Signature card
  • Mandate forms
  • KYC documents
  • Fixed deposit certificate

6. Retrieve Policy Documents

Retrieves all documents for a specific insurance policy.

Command Name: RetrievePolicyDocumentsListQuery

Request Parameters

ParameterTypeRequiredDescription
policyIdlongYesInsurance policy ID
documentTypeintegerNoFilter by document type
pageNumberintegerNoPage number (default: 1)
pageSizeintegerNoItems per page (default: 20)
isExportbooleanNoExport all results (default: false)

Request Example

{
"Cmd": "RetrievePolicyDocumentsListQuery",
"Data": {
"policyId": 99887,
"pageNumber": 1,
"pageSize": 20
}
}

Typical Policy Documents

  • Policy document
  • Premium payment receipts
  • Beneficiary designation forms
  • Claims documentation
  • Medical reports (for life insurance)

Storage Architecture

MinIO Object Storage

BankLingo uses MinIO as the primary document storage backend:

  • Scalability: Handles millions of documents
  • Redundancy: Configurable replication
  • Security: Encrypted at rest and in transit
  • Cost-Effective: S3-compatible object storage

File Organization

Documents are organized by entity type:

documents/
├── clients/
│ ├── {clientId}/
│ │ ├── document1_{guid}.pdf
│ │ └── document2_{guid}.jpg
├── loans/
│ ├── {loanId}/
│ │ └── document_{guid}.pdf
├── deposits/
│ ├── {depositId}/
│ │ └── document_{guid}.pdf
└── policies/
├── {policyId}/
└── document_{guid}.pdf

Metadata Storage

Document metadata is stored in the database:

  • File path and storage location
  • Entity associations
  • Upload timestamps
  • Document attributes (type, expiry, etc.)
  • User who uploaded

Common Use Cases

Example 1: Client Onboarding

Upload multiple KYC documents during client registration:

// Upload National ID
{
"Cmd": "CreateDocumentCommand",
"Data": {
"entityType": "Client",
"clientId": 12345,
"fileName": "national_id.pdf",
"fileContentBase64": "...",
"documentType": 1,
"documentTypeDescription": "National ID",
"documentNumber": "NIN-12345678",
"issueDate": "2015-06-20",
"expiryDate": "2025-06-19"
}
}

// Upload Utility Bill
{
"Cmd": "CreateDocumentCommand",
"Data": {
"entityType": "Client",
"clientId": 12345,
"fileName": "utility_bill.pdf",
"fileContentBase64": "...",
"documentType": 4,
"documentTypeDescription": "Utility Bill",
"issueDate": "2024-01-10"
}
}

Example 2: Loan Collateral Documentation

Attach property documents to a loan application:

{
"Cmd": "CreateDocumentCommand",
"Data": {
"entityType": "Loan",
"loanId": 67890,
"fileName": "property_valuation.pdf",
"fileContentBase64": "...",
"title": "Property Valuation Report",
"description": "Independent valuation for collateral property at 123 Main St",
"documentType": 6,
"documentTypeDescription": "Valuation Report",
"issueDate": "2024-01-15"
}
}

Example 3: Document Retrieval for Audit

Retrieve all expired documents requiring renewal:

{
"Cmd": "RetrieveDocumentsListQuery",
"Data": {
"endDate": "2024-01-20",
"documentType": 1,
"isExport": true
}
}

Example 4: Download Client Documents

Retrieve all documents for a specific client:

{
"Cmd": "RetrieveClientDocumentsListQuery",
"Data": {
"clientId": 12345,
"isExport": true
}
}

File Handling

Supported File Types

CategoryExtensionsMax Size
DocumentsPDF, DOC, DOCX10 MB
ImagesPNG, JPG, JPEG, GIF5 MB
SpreadsheetsXLS, XLSX, CSV10 MB
ArchivesZIP, RAR20 MB

Base64 Encoding

JavaScript example for encoding files:

function encodeFileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
// Remove data URL prefix (data:*/*;base64,)
const base64 = reader.result.split(',')[1];
resolve(base64);
};
reader.onerror = error => reject(error);
});
}

// Usage
const file = document.getElementById('fileInput').files[0];
const base64Content = await encodeFileToBase64(file);

Decoding for Download

When retrieving documents, the file path points to MinIO storage. Use the BankLingo file download API:

GET /api/files/download?path={filePath}
Authorization: Bearer <token>

Security Considerations

1. Access Control

  • Users can only access documents for entities they have permission to view
  • Role-based access controls apply
  • Audit trails track all document access

2. Encryption

  • Files encrypted at rest in MinIO
  • TLS encryption for data in transit
  • Secure base64 transmission

3. Virus Scanning

  • Optional virus scanning on upload
  • Quarantine of suspicious files
  • Automatic notification to administrators

4. Document Expiry

  • System tracks document expiry dates
  • Automated alerts for expiring documents
  • Workflow triggers for renewal processes

Best Practices

  1. Standardize File Names: Use clear, consistent naming conventions
  2. Add Descriptions: Include meaningful descriptions for easy identification
  3. Set Expiry Dates: Always set expiry dates for time-sensitive documents
  4. Document Type Consistency: Use standardized document types
  5. Regular Audits: Periodically review and purge obsolete documents
  6. Optimize File Sizes: Compress large files before upload
  7. Batch Operations: Use export functionality for bulk retrieval

Integration Notes

Document Lifecycle

Entity Associations

Documents are tightly coupled with banking entities:

  • Client Documents: Linked to customer profiles
  • Loan Documents: Attached to loan accounts
  • Deposit Documents: Associated with deposit accounts
  • Policy Documents: Connected to insurance policies

Related APIs:


Documentation Author: Owa Oluwasegun Tunbosun, Senior Platform Engineer