Skip to main content
To implement a multi-document processing scenario, create the following functions: CreateNewBatch AddDocumentToBatch RunBatchProcessing WaitFirstVerificationOrProcessedForMultiFileInvoice FetchingCapturedData MultiDocumentBatchIsProcessed

CreateNewBatch

The CreateNewBatch function creates a new batch and returns its identifier. There are no input parameters for this function. Output parameter type: int (batch identifier). Exceptions thrown: Exception. Java source:
// Creating FlexiCapture Web Services API client. 
// Please provide FlexiCapture Application Server address, tenant name, user name and password here. 
try (TenantClient tenantClient = new TenantClient(new URI(baseUri), tenantName, userName, password)) {
  // Getting the FlexiCapture project api. Please provide a project name here.
  try(ProjectApi projApi = tenantClient.getProjects().getProjectApi(multiFileProjectName)) {
    // Creating FlexiCapture batch and document.
    Batch batch = new Batch();
    Document doc = new Document();
    // Adding batch into FlexiCapture project.
    return projApi.getBatches().add(batch);
  }
} catch(Exception ex){
  // Chaining error messages. 
Throwable cause = ex.getCause();
String message = ex.getMessage();
while (cause != null) {
message += " " + cause.getMessage();
cause = cause.getCause();
}
// Throw chained message.
throw new Exception(message);
}

AddDocumentToBatch

The AddDocumentToBatch function adds a document to a batch. Input parameters:
NameJava typeDescription
batchIdintBatch identifier
fileNameStringName of the file
base64ContentStringFile contents in Base64 format
There are no output parameters for this function. Exceptions thrown: Exception. Java source:
// Creating FlexiCapture Web Services API client. 
// Please provide FlexiCapture Application Server address, tenant name, user name and password here. 
try (TenantClient tenantClient = new TenantClient(new URI(baseUri), tenantName, userName, password)) {
  // Getting the FlexiCapture project api. Please provide a project name here.
  try(ProjectApi projApi = tenantClient.getProjects().getProjectApi(multiFileProjectName)) {
    // Creating FlexiCapture document.
    Document doc = new Document();
    // Getting the FlexiCapture batch api. Please provide a batch identifier here.
    BatchApi batchApi = projApi.getBatches().getBatchApi(batchId);
    // Creating instance of file. 
    File file = new File(fileName, Base64.getDecoder().decode(base64Content.replace("\n", "").replace("\r", "")));
    // Adding document into FlexiCapture batch.
    // File is document content.
    batchApi.getDocuments().add(doc, file);
  }
} catch(Exception ex){
  // Chaining error messages. 
Throwable cause = ex.getCause();
String message = ex.getMessage();
while (cause != null) {
message += " " + cause.getMessage();
cause = cause.getCause();
}
// Throw chained message.
throw new Exception(message);
}

RunBatchProcessing

The RunBatchProcessing function initializes batch processing. Input parameters:
NameJava typeDescription
batchIdintBatch identifier
There are no output parameters for this function. Exceptions thrown: Exception. Java source:
// Creating FlexiCapture Web Services API client. 
// Please provide FlexiCapture Application Server address, tenant name, user name and password here. 
try (TenantClient tenantClient = new TenantClient(new URI(baseUri), tenantName, userName, password)) {
  // Getting the FlexiCapture project api. Please provide a project name here.
  try(ProjectApi projApi = tenantClient.getProjects().getProjectApi(multiFileProjectName)) {
    // Getting the FlexiCapture batch api. Please provide a batch identifier here.
    BatchApi batchApi = projApi.getBatches().getBatchApi(batchId);
    // Running the FlexiCapture batch for processing.
    batchApi.start();
  }
} catch(Exception ex){
  // Chaining error messages. 
Throwable cause = ex.getCause();
String message = ex.getMessage();
while (cause != null) {
message += " " + cause.getMessage();
cause = cause.getCause();
}
// Throw chained message.
throw new Exception(message);
}

WaitFirstVerificationOrProcessedForMultiFileInvoice

The WaitFirstVerificationOrProcessedForMultiFileInvoice function returns a verification URL. If the document has not reached the verification stage, an empty string is returned. Input parameters:
NameJava typeDescription
batchIdintBatch identifier
Output parameter type: String (verification URL). Exceptions thrown: Exception. Java source:
// Creating FlexiCapture Web Services API client. 
// Please provide FlexiCapture Application Server address, tenant name, user name and password here. 
try (TenantClient tenantClient = new TenantClient(new URI(baseUri), tenantName, userName, password)) {
  // Getting the FlexiCapture project api. Please provide a project name here.
  try(ProjectApi projApi = tenantClient.getProjects().getProjectApi(multiFileProjectName)) {
    // Getting the FlexiCapture batch api. Please provide a batch identifier here.
    BatchApi batchApi = projApi.getBatches().getBatchApi(batchId);
    // Waiting for the batch to be stopped on the verification stage and getting the FlexiCapture document.
    Document doc = batchApi.getDocuments().waitFirstVerificationOrProcessed();
    // Check if the batch stage is Verification.
    if (doc.getStageType() == ProcessingStageType.Verification) {
      // Returning first verification url string for FlexiCapture batch.
      return batchApi.getVerificationUrls(WebPageMode.Mini).get(0).toString();
    } 
    //Returning empty string if batch was processed without verification stage.
    return "";
  }
}catch(Exception ex){
  // Chaining error messages. 
Throwable cause = ex.getCause();
String message = ex.getMessage();
while (cause != null) {
message += " " + cause.getMessage();
cause = cause.getCause();
}
// Throw chained message.
throw new Exception(message);
}

FetchingCapturedData

The FetchingCapturedData function returns a list of output fields in JSON format. Input parameters:
NameJava typeDescription
batchIdintBatch identifier
templateNameStringDocument Definition name
Output parameter type: String (document fields in JSON format). Exceptions thrown: Exception. Java source:
// Creating FlexiCapture Web Services API client. 
// Please provide FlexiCapture Application Server address, tenant name, user name and password here. 
try (TenantClient tenantClient = new TenantClient(new URI(baseUri), tenantName, userName, password)) {
  // Getting the FlexiCapture project api. Please provide a project name here.
  try(ProjectApi projApi = tenantClient.getProjects().getProjectApi(multiFileProjectName)) {
    // Getting the FlexiCapture batch api. Please provide a batch identifier here.
    BatchApi batchApi = projApi.getBatches().getBatchApi(batchId);
    // Getting all documents from FlexiCapture batch.
    List<Document> documents = batchApi.getDocuments().getAll();
    for(Document document:
       documents){
      // Cheking document template name.
      if(document.getTemplateName().equals(templateName)){
        // Getting the FlexiCapture document api. Please provide a document identifier here.
        DocumentApi docApi = batchApi.getDocuments().getDocumentApi(document.getId());
        // Returning captured fields as a JSON string.
        return docApi.getExportedFields();
      }
    }
    //Returning empty JSON string if document template name not found.
    return "{}";
  }
}catch(Exception ex){
  // Chaining error messages. 
Throwable cause = ex.getCause();
String message = ex.getMessage();
while (cause != null) {
message += " " + cause.getMessage();
cause = cause.getCause();
}
// Throw chained message.
throw new Exception(message);
}

MultiDocumentBatchIsProcessed

The MultiDocumentBatchIsProcessed function returns a value that specifies whether the batch has been processed or not. Input parameters:
NameJava typeDescription
batchIdintBatch identifier
Output parameter type: boolean (true if the document is at the Processed stage and false otherwise). Exceptions thrown: Exception. Java source:
// Creating FlexiCapture Web Services API client. 
// Please provide FlexiCapture Application Server address, tenant name, user name and password here. 
try (TenantClient tenantClient = new TenantClient(new URI(baseUri), tenantName, userName, password)) {
  // Getting the FlexiCapture project api. Please provide a project name here.
  try(ProjectApi projApi = tenantClient.getProjects().getProjectApi(multiFileProjectName)) {
    // Getting the FlexiCapture batch api. Please provide a batch identifier here.
    BatchApi batchApi = projApi.getBatches().getBatchApi(batchId);
    // Waiting for the batch to be stopped on the verification or processed stage and getting the FlexiCapture document.
    Document doc = batchApi.getDocuments().waitFirstVerificationOrProcessed();
    // Check if the batch stage is Processed.
    return doc.getStageType() == ProcessingStageType.Processed;    
  }
}catch(Exception ex){
  // Chaining error messages. 
Throwable cause = ex.getCause();
String message = ex.getMessage();
while (cause != null) {
message += " " + cause.getMessage();
cause = cause.getCause();
}
// Throw chained message.
throw new Exception(message);
}