EndPoint Name: processdocument
EndPoint Details: This API is used to get the batch id for a single invoice (image/pdf) uploaded by the user.
Authorization: Bearer token as header
Request Type
URL/access/klearstack/processdocument
Request Body
Username for a particular user of a company
Password for a particular user of a company
file
processing_pref
document_type
invoice_type
Binary
string
string
string
Single image (pdf/jpeg/png) or native pdf file
Either “Speed” or “Accuracy” (It’s not case sensitive)
Type of document to be processed - “Invoices”,“Receipts”,“PurchaseOrders”,“NACH”,“LoanAgreement” or “Insurances”.
“B2B” for invoices commissioned by a business to another business directly.
“B2C” for invoices commissioned by a business to a consumer.
“B2C” for Insurances.
An identifier for correlating multiple documents. Example : Nach and FacilityAgreement should have same application_no.
additional_params (Optional)
For LoanAgreement : {
"borrower_name":"xyz",
"co_borrower":"abc",
"loan_amount_in_figures":250000,
"tenure":5,
"rate_of_interest":8.5,
"partner_name":"abc limited"
}
For Nach : {
"account_number":200382193
}
set_reference_number (Optional)
For adding document in Existing Set
For assigning Name to document set, it cannot be updated after set is created
create_new_set (Optional)
Flag needs to be True for creating new set, the param if set to True will create a new set with the given set_name and assign new set_reference_number to the document.
Shell
Copy curl -X POST "URL/access/klearstack/processdocument" \
-H "Authorization: Bearer your_token_here" \
-F "company_name=Replace_Company_Name_Here" \
-F "username=Replace_User_Name_Here" \
-F "password=Replace_Password_Here" \
-F "user_id=Replace_User_ID_Here" \
-F "user_role=Your_Role" \
-F "processing_pref=Speed" \
-F "document_type=Invoices" \
-F "invoice_type=B2B" \
-F "application_no=12345" \
-F "additional_params={\"borrower_name\":\"xyz\"}" \
-F "source_name=API" \
-F "priority_flag=true" \
-F "account_id=123456" \
-F "set_reference_number=Ref123" \
-F "set_name=MySet" \
-F "create_new_set=true" \
-F "file=@C:\Users\user\Downloads\xyz.pdf"
Python
Copy import requests
# API URL
url = "URL/access/klearstack/processdocument"
# Request payload
data={ 'company_name': 'Replace_Company_Name_Here',
'username': 'Replace_User_Name_Here',
'password': 'Replace_Password_Here',
'user_id': 'Replace_User_ID_Here',
'user_role': 'You_Role',
'processing_pref': 'Speed',
'document_type': 'Invoices',
'invoice_type': 'B2B',
'application_no': '12345',
'additional_params': '{"borrower_name":"xyz"}',
'source_name': 'API',
'priority_flag': 'true',
'account_id': '123456',
'set_reference_number': 'Ref123',
'set_name': 'MySet',
'create_new_set': 'true'
}
files=[
('file',('xyz.pdf',open('C:\\Users\\user\\Downloads\\xyz.pdf','rb'),'application/pdf'))
]
headers = {
'Authorization': 'Bearer your_token_here'
}
# Make the POST request
response = requests.request("POST", url, headers=headers, data=data, files=files)
# Print the response
if response.status_code == 200:
print(response.json())
else:
print("Error:", response.text)
Java
Copy import okhttp3.*;
import java.io.File;
import java.io.IOException;
public class ProcessDocumentAPI {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
// File to upload
File file = new File("C:\\Users\\user\\Downloads\\xyz.pdf");
// Create multipart request body
MultipartBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("company_name", "Replace_Company_Name_Here")
.addFormDataPart("username", "Replace_User_Name_Here")
.addFormDataPart("password", "Replace_Password_Here")
.addFormDataPart("user_id", "Replace_User_ID_Here")
.addFormDataPart("user_role", "Your_Role")
.addFormDataPart("processing_pref", "Speed")
.addFormDataPart("document_type", "Invoices")
.addFormDataPart("invoice_type", "B2B")
.addFormDataPart("application_no", "12345")
.addFormDataPart("additional_params", "{\"borrower_name\":\"xyz\"}")
.addFormDataPart("source_name", "API")
.addFormDataPart("priority_flag", "true")
.addFormDataPart("account_id", "123456")
.addFormDataPart("set_reference_number", "Ref123")
.addFormDataPart("set_name", "MySet")
.addFormDataPart("create_new_set", "true")
.addFormDataPart("file", "xyz.pdf",
RequestBody.create(MediaType.parse("application/pdf"), file))
.build();
Request request = new Request.Builder()
.url("URL/access/klearstack/processdocument")
.post(requestBody)
.addHeader("Authorization", "Bearer your_token_here")
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
System.out.println("Response: " + response.body().string());
} else {
System.out.println("Error: " + response.body().string());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Node.js
Copy const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const url = 'URL/access/klearstack/processdocument';
const formData = new FormData();
formData.append('company_name', 'Replace_Company_Name_Here');
formData.append('username', 'Replace_User_Name_Here');
formData.append('password', 'Replace_Password_Here');
formData.append('user_id', 'Replace_User_ID_Here');
formData.append('user_role', 'Your_Role');
formData.append('processing_pref', 'Speed');
formData.append('document_type', 'Invoices');
formData.append('invoice_type', 'B2B');
formData.append('application_no', '12345');
formData.append('additional_params', '{"borrower_name":"xyz"}');
formData.append('source_name', 'API');
formData.append('priority_flag', 'true');
formData.append('account_id', '123456');
formData.append('set_reference_number', 'Ref123');
formData.append('set_name', 'MySet');
formData.append('create_new_set', 'true');
formData.append('file', fs.createReadStream('C:\\Users\\user\\Downloads\\xyz.pdf'));
axios.post(url, formData, {
headers: {
...formData.getHeaders(),
'Authorization': 'Bearer your_token_here'
}
})
.then(response => console.log(response.data))
.catch(error => console.error('Error:', error.response ? error.response.data : error.message));
JavaScript (XMLHttpRequest)
Copy var formData = new FormData();
formData.append('company_name', 'Replace_Company_Name_Here');
formData.append('username', 'Replace_User_Name_Here');
formData.append('password', 'Replace_Password_Here');
formData.append('user_id', 'Replace_User_ID_Here');
formData.append('user_role', 'Your_Role');
formData.append('processing_pref', 'Speed');
formData.append('document_type', 'Invoices');
formData.append('invoice_type', 'B2B');
formData.append('application_no', '12345');
formData.append('additional_params', '{"borrower_name":"xyz"}');
formData.append('source_name', 'API');
formData.append('priority_flag', 'true');
formData.append('account_id', '123456');
formData.append('set_reference_number', 'Ref123');
formData.append('set_name', 'MySet');
formData.append('create_new_set', 'true');
// File input (Replace 'fileInput' with the actual file input element in your HTML)
var fileInput = document.querySelector('input[type="file"]');
if (fileInput.files.length > 0) {
formData.append('file', fileInput.files[0]);
}
var xhr = new XMLHttpRequest();
xhr.open("POST", "URL/access/klearstack/processdocument", true);
xhr.setRequestHeader("Authorization", "Bearer your_token_here");
// Handle response
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log("Response:", xhr.responseText);
} else {
console.error("Error:", xhr.responseText);
}
}
};
// Send request
xhr.send(formData);
API Response
{
"OCR_ref_no": "faaf38a9-2cc7-4b2b-89f2-182252d1638c",
"status": "pass",
"description": "",
"application_no": "",
"release_version": “7.8.9”,
"set_reference_number":"12345"
}
{"error": "Please provide username."}
{"error": "Please provide password."}