Back to blog
Articles

You Too Can Be a Programmer: How Generative AI Can Upskill Any eDiscovery Professional to Write Code (Part 2)

Jay Leib
November 15, 2024

15 min read

Check how Reveal can help your business.

Schedule demo

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.

What Is an API?

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.

Why APIs Matter in eDiscovery

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.  

How Generative AI Helps

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.  

Key Terms to Know

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.

Connecting to the Reveal API

Step 1: Visit the Reveal Swagger Page

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.)  

Step 2: Write a Prompt to Build a Reveal API Test Harness Application

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):  

The Prompt:

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.  

Expected Code:

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!

Explanation of the Code:  

Let’s break down what each part of the code does.

Import Necessary Libraries

  • Import requests: A library used to send HTTP requests easily.
  • From getpass import getpass: Allows secure input of passwords without displaying them on the screen.

Authenticate Function

  • Purpose: Sends a POST request to the authentication endpoint with the provided username and password.
  • Process: Constructs the authentication URL and data payload.
  • Sends the request and checks the response status code.
  • If successful, extracts and returns the authentication token.
  • If not, prints an error message and exits.

Get Projects Function

  • Purpose: Retrieves the list of projects available to the authenticated user.
  • Process: Sets the projects endpoint URL.
  • Includes the authentication token in the request headers.
  • Sends a GET request to retrieve the projects.
  • Parses and returns the JSON response if successful.

Step 3: Now let's find a cozy home for our code! Many online platforms are available, but Google Colab definitely ranks among the elite.

  • Go to Google Colab and click Sign In.
  • Use your Google account or click Create account to register.
  • After logging in, click File > New Notebook to create a new Jupyter notebook.
  • In the new notebook, click on the Code cell and paste your Python code.
  • Press Shift + Enter or click the Play button to run the code.
  • Your output will display below the code cell.

PUT THINGS TOGETHER: Using Generative AI to Build Your Application

Choose an IDE (Integrated Development Environment)

Generate the Code with AI

  • Input the prompt into your chosen Generative AI tool.
  • Review the code it generates carefully and update as necessary.
  • Replace placeholders with actual values (end points, username, password, etc.)

Cut and Paste the Code into Your IDE

  • Copy the generated code.
  • Paste it into your IDE.

Trial and Error

  • Run the code to see if it works.
  • If you encounter errors, don’t worry—this is a normal part of programming.
  • Use Generative AI to help troubleshoot by describing the error messages or issues you’re facing.

Customize as Needed

  • Adjust the code to better fit your specific needs.
  • You can ask the AI tool to modify parts of the code or add new features.
  • For example, you might want to display additional project details or handle exceptions differently.

Important Reminders

Credentials and Permissions:

  • You will need your Reveal username and password.
  • Ensure you have the necessary permissions within Reveal Enterprise to access the API.

Security Considerations:

  • Handle your credentials securely.
  • Avoid sharing your username and password.
  • Do not hardcode sensitive information into your scripts.

Encouragement to Save Your Code on GitHub for the eDiscovery Community

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

Conclusion

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.

About the Authors

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.

Get exclusive AI & eDiscovery
insights in your inbox

I confirm that I have read Reveal’s Privacy Policy and agree with it.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.