Locked bank statements and payslips in a document workflow
Bank statements, payslips and tax forms often arrive password-protected. A safe pattern to unlock, process and store them, and where to keep the passwords.
Loan applications, accounting tools and tenant screening all ask users for bank statements and payslips. Banks and payroll providers often send these as password-protected PDFs. Your workflow then fails at the first step that needs to read the file. Here is a pattern that handles it cleanly.
1. Detect the lock early
Run the first real step on the file, such as a merge or compression. If it fails with encrypted_pdf, the file is locked. That error is free, so detection costs nothing. Ask the user for the password at that moment, while they still have the file in front of them.
2. Unlock with the password
Call the PDF Unlock API with the password:
curl https://api.justapi.tech/v1/pdf/unlock \
-H "Authorization: Bearer ak_live_..." \
-H "Content-Type: application/json" \
-d '{"source": {"url": "https://uploads.example.com/u_8812/statement-oct.pdf"}, "options": {"password": "user-supplied"}}'
A wrong password returns encrypted_pdf again, also free, so you can show "That password did not work" and let the user retry.
3. Process the unlocked copy
Pass result.file_id from the unlock call as the source of the next step. Typical chains:
- Unlock, then merge three months of statements into one file.
- Unlock, then extract the summary page.
- Unlock, then compress for upload limits.
4. Decide what you store
The unlocked copy is readable by anyone who gets it. Decide on purpose:
- Store the original, locked file plus the password in a secrets store if you need to reprocess later.
- Or store the processed file protected again, with the PDF Protect API and a password only your app knows.
- Acknowledge the unlocked result with
POST /v1/files/{id}/ackonce you have it, so it is deleted from our storage at once instead of after 24 hours.
Where passwords should not go
Not in logs, not in the job metadata you send us, not in the file name. JustAPI does not store the password you send to unlock or protect: the job only records that one was set. Your own system should be at least as careful.
Cost of the whole chain
Each call is billed on its own: $0.005 for the unlock at the first tier, plus the next step. Every failed call along the way is free.