How to bulk eFile to courts using REST APIs and Java (Example)

This guide describes how you can use JAVA programming language and eFiling APIs to file documents into courts. You, however, can use any other languages (.NET, Python, etc.) to integrate with the court’s eFiling system if JAVA does not meet your requirement.

Currently API based eFiling is supported in the following court system.

1. Texas
2. Illinois
3. Indiana
4. California (Tyler courts, Los Angeles, Placer, Riverside)
5. Maryland
6. Florida

1. You have two return of service PDF files (return_service_1.pdf, return_service_2.pdf) sitting in a folder on your desktop and you want to efile them into TX court systems.
2. You also have a CSV file (data.csv) with additional information about those two return of service PDF files. Here the CSV file is acting like a database table.

Content of data.csv

County Name

Case Number

File Path

Filing Party

Harris District

200558231

c:/apps/pdfs/return_service_1.pdf

Json

Dallas Civil

200558232

c:/apps/pdfs/return_service_2.pdf

Smith

You want to bulk efile these documents to TX court systems. Note: the same code can be reused for filing into any other states.

You need the following information to start the development.

Name

Example Value

Notes

clienttoken

DEMO777

If you do not have the clienttoken, email efile@uslegalpro.com with your name and company information to get one

endpoint_base

https://api.uslegalpro.com/v2/tx

This is for Texas but same pattern will follow for other states

username

efile@example.com 

You can create a user account by registering at https://uslegalpro.com

password

password123

You will need to write following efiling related functionality at the minimum

1. Authenticate to court’s eFiling system
2. eFile into the court system
3. Check status of the filing from the court system once filed (Optional)
4. Download court stamped document (Optional)

Additionally you will need to create a code to loop through each line in the CSV file (data.csv) and call eFile functionality.

1) Authenticate

Write a java method that allows user@example.com to authenticate against the court's eFiling system.

The following method  (getAuthToken) reads content of authenticate.json and replaces  and  parameters with actual username and password passed in the method and then calls a https://api.uslegalpro.com/v2/tx/user/authenticate” rel=”nofollow”> REST API  to authenticate the user. The method returns an auth token which will be used for subsequent calls.

public static String getAuthToken(String endpoint_base, String username, String password, String clienttoken) throws Exception {
                String body = FileUtils.readFileToString(
new File(jsonlocation_root + "/authenticate.json"), "UTF-8");
                Map keyValue =
new HashMap();
                keyValue.put(
"username", username);
                keyValue.put(
"password", password);
                body = StringSubstitutor.replace(body, keyValue);
                JSONObject jsonObject = callRest(endpoint_base +
"/user/authenticate", "clienttoken", clientoken, HttpMethod.POST, body);
                String auth_token = jsonObject.getJSONObject(
"item").getString("auth_token");
                
return auth_token;
}

Content of authenticate.json referenced in method (above)

{
   "data": {
       "username":
"",
       "password":
""
   }
}

Response

{
 
"item": {
   
"auth_token": "3a670351-0a7f-4201-8b3d-2d6b9ce9d05f/DEMO777/bdd93ca3-3faa-43c3-893e-15831734c3f3"
 }
}

2) eFile

Write a java method that allows for eFiling into the court’s system using the auth token returned by getAuthToken method

The method reads content of efile.json and replaces , ,  and  parameters with actual values read from the CSV file and passed to this method and calls a REST api (https://api.uslegalpro.com/v2/tx/efile) to efile.

public static JSONObject efile(String authtoken, String casenumber, String leadfile, String attachment, String filingparty) throws Exception {
                String body = FileUtils.readFileToString(
new File(jsonlocation_root + "/efile.json"), "UTF-8");
                Map keyValue =
new HashMap();
                keyValue.put(
"casenumber", casenumber);
                keyValue.put(
"leadfile", leadfile);
                keyValue.put(
"attachment", attachment);
                keyValue.put(
"filingparty", filingparty);
                body = StringSubstitutor.replace(body, keyValue);
                JSONObject jsonObject = callRest(endpoint_root +
"/efile", "authtoken", authtoken, HttpMethod.POST, body);
                
return jsonObject.getJSONObject("item");
}

Content of efile.json  referenced in method (above)

{
 "data": {
   "jurisdiction":
"(''.equals('')",
   "case_number":
"",
   "payment_account_id":
"(''.equals('Credit Card 1'))",
   "filing_party_id":
"(''.startsWith(''))",
   "filer_type":
"(''.contains('Non-Party'))",
   "filings": [
     {
       "doc_type":
"(''.startsWith('Affidavits'))",
       "type":
"EFile",
       "code":
"(''.startsWith('No Fee'))",
       "description":
"No Fee Documents",
       "file":
""
     }
   ]
 }
}

Response

{
   
"item": {
       
"filings": [{
           
"code": "136718",
           
"id": "e598b822-b0e4-4023-a1dd-84885ffba620",
            "status": "submitting"
       }],
       
"id": "223535",
       
"case_tracking_id": "775dd127-3b77-42b0-862a-a8b3c16052b5"
   },
   
"message_code": 0
}

3) Get Filing Status

Write a program to get status of submitted filing from the court system.

The method calls a REST api (https://api.uslegalpro.com/v2/tx/filing/filing_id) to get the status of the filing.  Once the clerk of the court accepts the filing, the response will also have a link to a stamped PDF in stamped_document node  which can be used to download the content locally.

public static JSONObject getFilingStatus(String endpoint_base, String authtoken, String id) throws Exception {
                JSONObject jsonObject = callRest(endpoint_base +
"/filing/" + id, "authtoken", authtoken, HttpMethod.GET, null);
                
return jsonObject;
}

Response

{
 
"item": {
   
"assigned_judge": "",
   
"jurisdiction": "harris:dc246ivd4",
   
"case_title": "DAGGY, MELANIE GAEL v BILLEY, DANA NADINE",
   
"case_category_display": "Family - Other Family Law",
   
"submitted_on": "2021-09-24T23:28:45.0Z",
   
"filings": [
     {
       
"code_display": "No Fee Documents",
       
"code": "136718",
       
"file": "dummy.pdf",
       
"stamped_document": "https://filerstage.efiletexas.gov/DownloadResource.ashx?RID=6b051078-30ae-42e7-9a03-e9c664e2b322",
        "doc_code": "332",
       
"original_document": "https://ezstage.s3.us-east-2.amazonaws.com/3d436eb4-e40f-4b99-b02e-f9044dc1087a?response-content-disposition=attachment%3B%20filename%3Ddummy.pdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210924T234330Z&X-Amz-SignedHeaders=host&X-Amz-Expires=900&X-Amz-Credential=AKIAICIYLMUYPA2HMTYQ%2F20210924%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Signature=4f57715d7cdc0a2b68bfd8e8d1d1d3cb71b064327b2a1b79a6b52fabd6b799be",
       
"description": "No Fee Documents",
       
"doc_type": "53656",
       
"doc_type_display": "Affidavits"
     }
   ],
   
"envelope_fees": {
     
"convenience_fee": "0.00",
     
"total_service_tax_fees": "0.00",
     
"total_court_filing_fees": "0.00",
     
"total_court_service_fees": "0.00",
     
"total_court_case_fees": "0.00",
     
"total_court_party_fees": "0.00",
     
"total_mail_service_fees": "0.00",
     
"total_filing_&_service_fees": "0.00",
     
"total_provider_service_fees": "0.00",
     
"grand_total": "0.00",
     
"total_redaction_fees": "0.00",
     
"total_provider_tax_fees": "0.00"
   },
   
"payment": {
     
"transaction_id": "58176",
     
"last4_digit": "1111",
     
"transaction_response": "",
     
"transaction_amount": "0.00",
     
"name": "Credit Card 1",
     
"waiver_indicator": "false",
     
"expire_month": "4",
     
"expire_year": "2022",
     
"card_type": "VISA",
     
"order_id": ""
   },
   
"case_number": "200558233",
   
"submitter_name": "eFile  User",
   
"client_matter_number": "1",
   
"id": "89af16ce-bb3a-4da2-9690-f78a0e10d58c",
   
"status_reason": "",
   
"case_tracking_id": "775dd127-3b77-42b0-862a-a8b3c16052b5",
   
"jurisdiction_display": "Harris DC - 246th IV-D Court 4",
   
"envelope_id": "223536",
   
"filing_fees": {
     
"filing_&_service_fee": "0.00",
     
"filing_court_fees": "0.00",
     
"filing_fee": "0.00"
   },
   
"case_type": "53251",
   
"reviewer_comment": "",
   
"submitter_email": "efile.demo@uslegalpro.com",
   
"accepted_on": "2021-09-24T23:40:50.0Z",
   
"case_category": "210",
   
"case_type_display": "Sapcr - Custody",
   
"filing_party_id": "5686df58-c73b-4946-852c-5fe2912c7911",
   
"status": "accepted"
 },
 
"message_code": 0
}

3) Put it all together

Write a program that reads CSV rows and processes them one by one

package com.uslegalpro;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.text.StringSubstitutor;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class Efile {
        
        
static String endpoint_base = "https://api-stage.uslegalpro.com/v2/tx";
        
static String clientoken = "DEMO7771";
        
static String jsonlocation_root = "c:/stage/json";
        
        
//Main method that reads the CSV files and processes each line.
        
public static void main(String args[]) throws Exception {        
                
                String email =
"efile.demo@uslegalpro.com";
                String password =
"password";
                String authtoken = getAuthToken(endpoint_base, clientoken, email, password);
                
                String file =
"c:/stage/data/data.csv";
                List filingids =
new ArrayList();
            
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
                String line =
"";
                
while ((line = br.readLine()) != null) {
                    String attibutes[] = line.split(
",");
                    String jurisdiction = attibutes[
0];
                    String casenumber = attibutes[
1];
                    String filepath = attibutes[
2];
                    String filingparty = attibutes[
3];
                    JSONObject jo = efile(endpoint_base, authtoken, jurisdiction, casenumber, filepath, filingparty);
                                JSONObject filing = jo.getJSONArray(
"filings").getJSONObject(0);
                                String filingid = filing.getString(
"id"); //You can store this in database
                                filingids.add(filingid);
                }
            }
catch (FileNotFoundException e) {
                    e.printStackTrace();
            }
            
            
//Following lines of code can be executed occasionally to check the status of the filing
            
for(String filingid: filingids) {
                    JSONObject filingStatus = getFilingStatus(endpoint_base, authtoken, filingid);
                    System.out.println(filingStatus);
            }
            
        }
        
        
//Method that returns auth token
        
public static String getAuthToken(String endpoint_base, String clienttoken, String username, String password) throws Exception {
                String body = FileUtils.readFileToString(
new File(jsonlocation_root + "/authenticate.json"), "UTF-8");
                Map keyValue =
new HashMap();
                keyValue.put(
"username", username);
                keyValue.put(
"password", password);
                body = StringSubstitutor.replace(body, keyValue);
                JSONObject jsonObject = callRest(endpoint_base +
"/user/authenticate", "clienttoken", clientoken, HttpMethod.POST, body);
                System.out.println(jsonObject.toString(
4));
                String auth_token = jsonObject.getJSONObject(
"item").getString("auth_token");
                
return auth_token;
        }
        
        
//Method that does the efiling
        
public static JSONObject efile(String endpoint_base, String authtoken, String jurisdiction, String casenumber, String leadfile, String filingparty) throws Exception {
                String body = FileUtils.readFileToString(
new File(jsonlocation_root + "/efile.json"), "UTF-8");
                Map keyValue =
new HashMap();
                keyValue.put(
"jurisdiction", jurisdiction);
                keyValue.put(
"casenumber", casenumber);
                keyValue.put(
"leadfile", leadfile);
                keyValue.put(
"filingparty", filingparty);
                body = StringSubstitutor.replace(body, keyValue);
                JSONObject jsonObject = callRest(endpoint_base +
"/efile", "authtoken", authtoken, HttpMethod.POST, body);
                System.out.println(jsonObject.toString(
4));
                
return jsonObject.getJSONObject("item");
        }
        
        
//Method that gets filing status
        
public static JSONObject getFilingStatus(String endpoint_base, String authtoken, String id) throws Exception {
                JSONObject jsonObject = callRest(endpoint_base +
"/filing/" + id, "authtoken", authtoken, HttpMethod.GET, null);
                
return jsonObject;
        }
        
        
//Method that calls the REST API
        
public static JSONObject callRest(String url, String tokenname, String tokenvalue, HttpMethod method, String data) throws Exception {
                RestTemplate restTemplate =
new RestTemplate();
                HttpHeaders headers =
new HttpHeaders();
                headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
                headers.setContentType(MediaType.APPLICATION_JSON);
                headers.set(tokenname, tokenvalue);
                HttpEntity entity =
new HttpEntity(data, headers);
                ResponseEntity respEntity = restTemplate.exchange(url, method, entity, String.class);
                
return new JSONObject(respEntity.getBody());
        }
}