This document guides you through how to use LeanLaw's Public API, including how to generate an API key in your firm's settings, how to use that key to authenticate and use with LeanLaw's GraphQL API, and how to pass queries on our API Explorer. To learn more about what our Public API is and what it can do for you, check out our Introduction to Public API document.

We've also provided a quick video demonstration of our public API.

Table of Contents:


How to Generate an API Key


API keys are associated with the firm and not to a single user. You need an API key in order to authenticate a service with LeanLaw and access your firm's data. For security reasons, you should never share your key with anyone.

1. Go to Settings

Go to your firm's Settings page by clicking the gear icon ⚙️ in the top right corner of your page.

2. Go to API

In your firm's Settings page, click on API underneath the Integrations heading.

3. Click Generate API Key

In the API page of your firm's Settings, click the green Generate API Key button. This will give you the option to name your new API key.

4. Name your API Key and Save

Give a name to your API key. This name can be anything you'd like, such as the name of the user who's creating the key or the service it's intended for.

You now have an API key you can use for authentication. Note the Copy to Clipboard button provided for easily transferring your key. To test your key, consider following the next section, How to Use the API Explorer.


How to authenticate with the API Explorer


The API Explorer is a site we created to let you view the schema--the list of queries you can use with our API key--and use them in a test environment. You can visit the API explorer at https://graph.myleanlaw.co/graphql or by clicking API Explorer link in the API page of your firm's Settings.

In order to get any data from your requests, you need to authenticate with your API key. In the API Explorer, this is done in the HTTP header.

1. Click Operation Settings to open the HTTP header

In the API Explorer, open your HTTP header by clicking the icon with three horizontal bars, called Operation Settings, indicated in the picture below.

A screenshow of the API Explorer with the operation settings indicated.

2. Set up your API Key

In the HTTP header, click the blank space on line 2 so you can type or paste the following following:

"x-leanlaw-apikey":

With a space entered after the colon, paste your API key between quotes. Your header should now look like the entry below, with your API Key in place of the 9s.

{
"x-leanlaw-apikey": "99999999-9999-9999-9999-999999999999"
}

A screenshot of the HTTP header with proper API key entry.

The API Explorer is now authenticated with your API key, and you're ready to start entering queries.


Testing your API key


The following is a simple test you can run to make sure your API key is working, and get acquainted with the API explorer. Typing the following query should retrieve a list of your firm's matter names and their universally unique identifiers (UUIDs).

query {
matters {
items {
id
name
}
}
}

Note: Copying the above text may not copy the line breaks. Line breaks aren't mandatory; they're just for organization. However, proper spacing and capitalization *are* mandatory.


Query tools: Schema and autocomplete


The Explorer provides two valuable tools for finding compatible GraphQL requests, the Schema and control + spacebar suggestions.

API Schema

In the API Explorer, on the left side, click the book icon called Schema.

A screenshot of the API Explorer with the Schema icon indicated.

The schema lists all query requests recognized by our API. It also indicates the compatible nesting order of requests. For example, if you open schema and click on Clients, you'll see that a tab opens up showing you what can be nested inside Clients. In this new tab, you'll see Items; if you click on Items, you'll see what can be nested inside Items, and so forth. Using the Schema, you can determine proper request and request ordering to make requests like:

query {
clients {
items {
name
contact {
firstName
lastName
email
}
}
}
}

to request a list of all your clients' (company) names as well as the first name, last name, and email from their contact information.

Autocomplete (Control + Spacebar)

The API Explorer also offers autocomplete suggestions. If you hold control and press spacebar while you're typing in the console, API Explorer will drop down a list of viable requests. The below gif demonstrates how the autocomplete can be used to discover viable requests--note how you'll still need to enter spaces and braces.

A gif showing the Autocomplete function in the API Explorer.

Getting more results


LeanLaw API paginates search results with a limit of 1000 lines per page. Because of this, some requests may retrieve too much data to fit in the API Explorer. The tools listed in this section will help you check if you have more data than is being displayed, skip or take specific data, and sort your search results.

Using pageInfo{hasNextPage to check if more data is available

Adding pageInfo{hasNextPage into an item request asks the system if your request has another page of results that didn't fit in the page. If there is another page, this property will return "True" in your results. If there isn't another page, this property will return "False."

query { 
clients {
items {
name
}
pageInfo{hasNextPage
}
}
}

The above request will retrieve all available client names and then answer the pageInfo query, informing you whether or not the results have another page you can't see.

Iterating searches with take and skip

If you have more data than you can fit on a single page, the arguments skip and take will be useful to you. Skip x tells the API not to retrieve the next x number of results. Skip and take are used in parentheses immediately following a property, before that property's brace, as demonstrated below:

query {
clients(skip: 10, take: 5) {
items {
name
}
}
}

The above query will skip results 0-10 and take only the next 5 after that, retrieving results 11-15. By using one or both of these properties, you can skip through the 1000 results you've already seen or limit your results for a certain search so you're able to fit other data on a page.

Sorting data with ASC and DESC

ASC (ascending) and DESC (descending) can be used to rearrange data in the order that matters to you. They must be used inside braces following the order command, and the order command must be within parentheses. For example:

query { 
matters(order: {
name: ASC
reference: DESC
}) {
items {
name
reference
}
}
}

As you can see, multiple ordering properties can be applied to the same results. In the above example, a query is retrieved for all matters by name and reference (matter ID); the matters are sorted first in ascending order by name and, in the event that any matter names are duplicated, those duplicates will be sorted in descending order by reference.


More code samples


curl

The following snippet shows the curl command to fetch a list of clients from the API:

>curl \
> -H "x-leanlaw-apikey: <leanlaw-apikey>" \
> -H "Content-Type: application/json" \
> -d "{\"query\": \"{clients{items{id,name}}}\"}" \
> https://graph.myleanlaw.co/graphql

Nodejs

The following snippet fetches a list of clients from the API.

const client = require('https')

const data = JSON.stringify({
query: "{clients{items{id,name}}}"
})

const options = {
hostname: 'graph.myleanlaw.co',
path: '/graphql',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-leanlaw-apikey': 'leanlaw api key'
})
}

const req = client.request(options, res => {
res.on('data', d => {
process.stdout.write(d);
})
}

const req = client.request(options, res => {
res.on('data', d => {
process.stdout.write(d);
})
})

req.on('error', e => {
console.error(e)
})

req.write(data)
req.end()

Did this answer your question?