Use cases
Industries
Products
Resources
Company
In our previous article in LegalTech News, we took our first steps into programming by creating a simple data organizer with the help of Generative AI tools like ChatGPT and Claude. Now, we’re ready to explore how to connect to eDiscovery platform APIs, specifically the Reveal API, by using Generative AI to write code for us. This guide is designed to help you unlock new ways to automate and enhance your eDiscovery workflows, even if you’re new to programming.
An API (Application Programming Interface) is a set of rules and protocols that allows different software applications to communicate with each other. Think of it as a messenger that takes your requests, tells a system what you want it to do, and then returns the response back to you.
In eDiscovery, APIs can:
Automate Repetitive Tasks: Reduce manual data entry and save time.
Integrate Systems: Connect different software tools for a seamless workflow.
Access Data Programmatically: Retrieve, update, or analyze data in bulk without navigating through multiple screens.
For example, you could use an API to pull all documents tagged as “High Priority” from your case database with a single command or update metadata across numerous documents automatically. For this article, we will use AI to generate code to connect to Reveal’s API and retrieve a list of projects.
With Generative AI tools, you don’t need extensive coding knowledge to work with APIs. You can let AI generate code base and update it to fit your need:
Generate Code Snippets: Describe what you want, and let AI create the code base for you.
Simplify Documentation: Ask AI to explain complex API endpoints or parameters in simpler terms.
Customize Solutions: Adjust scripts to meet your specific needs without starting from scratch.
Before we dive in, let’s clarify some essential terms:
• HTTP Methods: Actions you can perform using APIs:
• GET: Retrieve data.
• POST: Create new data.
• PUT/PATCH: Update existing data.
• DELETE: Remove data.
• Endpoints: Specific URLs where API services are available, each performing a particular function.
• Parameters: Additional data sent with your API request to specify what you want, like filters or search criteria.
• Headers: Key-value pairs sent with the request to provide metadata, such as authentication tokens or content types.
• JSON (JavaScript Object Notation): A lightweight format for data exchange, easy for both humans and machines to read and write.
• Authentication Tokens: Keys that verify your identity to access the API.
• Swagger: A framework for describing APIs. The Reveal Swagger page provides interactive documentation where you can test API calls directly in your browser.
• Jupyter Notebook: An open-source web application for creating, sharing documents with live code, equations, visualizations, and text.
• Google Colab: A free cloud service for running Python code in Jupyter notebooks through your web browser.
Navigate to the Reveal Swagger page. This page lists all available API endpoints, their parameters, and allows you to test API calls. (Note: Please refer to your Reveal platform documentation or contact your administrator for the URL.)
Now, let’s use a Generative AI tool to help us write the code for an API Test Harness application. To write a good prompt, we need knowledge of API calls such as the path of the endpoints, what parameters it requires, and the structure of the response (see Key terms above).
After playing with prompts a few times, below is the one we came up with which gives ready-to-use code (the code below is generated by OpenAI’s GPT-4o model):
I would like you to write code in Python for an API testing for Reveal. The code needs to be compatible with Jupyter Notebook.
Please read the Reveal API documentation below before you start:
https://consulting.us-east-1.reveal11.cloud/rest/api-docs/index.html?urls.primaryName=v2
Here are the request details:
I would like the code to first read username and password secrets from Colab, assume user has created two secrets in Colab, USER and PASSWORD. I would like the code then send a POST request to the endpoint defined at "/api/v2/login", if successful, parse the response to get loginSessionId and userId and store it.
Then I would like to make a second "GET" request to the endpoint defined at "/api/v2/projects", passing userId retrieved above as one of the parameters. If the request is successful, print project names (defined by "projectName" property) line by line.
Please make sure to add proper headers (Content-Type, method, user-agent) when making HTTP requests. For the 2nd request, please also add an extra header "incontrolauthtoken" using the value of loginSessionId retrieved from the first request.
import requests
import os
# Step 1: Retrieve USER and PASSWORD secrets from Colab
username = os.environ.get('USER')
password = os.environ.get('PASSWORD')
if not username or not password:
raise ValueError("Secrets USER and PASSWORD must be set in Colab.")
# Step 2: Define the authentication function
def authenticate(username, password):
"""
Authenticates with the Reveal API using username and password.
Returns loginSessionId and userId if authentication is successful.
"""
login_url = "https://consulting.us-east-1.reveal11.cloud/rest/api/v2/login"
login_data = {
"username": username,
"password": password
}
# Define headers for the POST request
headers = {
"Content-Type": "application/json",
"User-Agent": "Reveal-API-Tester/1.0"
}
# Send POST request to login
response = requests.post(login_url, json=login_data, headers=headers)
response.raise_for_status() # Raise an error if the request fails
# Parse the response to get loginSessionId and userId
login_response = response.json()
login_session_id = login_response.get("loginSessionId")
user_id = login_response.get("userId")
if not login_session_id or not user_id:
raise ValueError("Failed to retrieve loginSessionId and userId from login response.")
print("Authentication successful!")
return login_session_id, user_id
# Step 3: Define the function to retrieve projects
def get_projects(login_session_id, user_id):
"""
Retrieves a list of projects for the authenticated user and prints each project name.
"""
projects_url = "https://consulting.us-east-1.reveal11.cloud/rest/api/v2/projects"
# Set headers for the GET request, including the incontrolauthtoken
headers = {
"Authorization": f"Bearer {login_session_id}",
"incontrolauthtoken": login_session_id,
"User-Agent": "Reveal-API-Tester/1.0",
"Accept": "application/json"
}
# Parameters for GET request
params = {"userId": user_id}
# Send GET request to retrieve projects
response = requests.get(projects_url, headers=headers, params=params)
response.raise_for_status() # Raise an error if the request fails
# Parse the response to get project list
projects_response = response.json()
projects = projects_response.get("results", [])
# Print each project name
if projects:
print("Project Names:")
for project in projects:
print(project.get("projectName", "Unnamed Project"))
else:
print("No projects found.")
# Main Execution
try:
# Step 1: Authenticate to get session ID and user ID
session_id, user_id = authenticate(username, password)
# Step 2: Retrieve and print project names
get_projects(session_id, user_id)
except requests.exceptions.RequestException as e:
print(f"API request failed: {e}")
except ValueError as e:
print(f"Error: {e}")
WHOA! We now have the Python code ready to go to login to Reveal and retrieve a list of projects you have access to!
Let’s break down what each part of the code does.
Import Necessary Libraries
Authenticate Function
Get Projects Function
Credentials and Permissions:
Security Considerations:
As you start building these applications, we encourage you to save your work on GitHub. Here, you can share your scripts, collaborate with others, and see what others are building. Saving your work to GitHub also allows you to track changes, maintain a version history, and contribute to a broader community of professionals enhancing legal technology.
For the sample code above, we have cleaned it up, made necessary updates and published it as a working Jupyter Notebook in the following GitHub public repository: https://github.com/LTProgrammer/eDiscovery
As we wrap up this two-part journey, it’s time to reflect on the transformation you’ve undergone. Just like the Green Lantern harnesses the limitless power of his ring through sheer will and creativity, you’ve learned to wield the power of Generative AI to bring your ideas to life. Your creativity is your true superpower, and Generative AI is the ring that channels it.
By embracing these tools, you’ve unlocked new possibilities:
Be More Self-Sufficient: Build tools without needing advanced degrees.
Enhanced Integration: Connect systems in ways that were previously out of reach.
Expanded Skill Set: Evolve from an eDiscovery professional into a tech-savvy innovator.
Remember, the Green Lantern’s ring is limited only by the user’s imagination and willpower. Similarly, with Generative AI at your fingertips, the only limits are the ones you set for yourself. Continue to explore, experiment, and expand your horizons.
This concludes our two-part series on using Generative AI to build applications, scripts, and work with APIs. We hope this empowers you to take charge of technology rather than being confined by it. Your new skills not only enhance your current role but also position you as a leader in the evolving landscape of eDiscovery.
Jay Leib and YE Chen are industry veterans in eDiscovery and technology innovation, having worked together in the field for 25 years. Jay is the Chief Strategy and Innovation Officer at Reveal, a leading AI company in eDiscovery. YE Chen is the AI Solution Architect at Reveal, specializing in the integration of advanced machine learning techniques to streamline and enhance legal workflows. Together, they are dedicated to helping eDiscovery professionals leverage AI to build more effective and efficient solutions. To reach the authors, or if you’d like to contribute to the eDiscovery public Github repository email: jleib@revealdata.com.
For more resources and future articles, visit the Reveal blog.