0

I have only used wrappers to access this httr library in the past and could use help with a new pull from the courtlistener API. This code (below) retrieves records, but does not use the query items:

query_params <- list(
    q = "defamation OR libel OR slander",  # Search for relevant cases   
    date_filed_min = "2023-01-01",  # Start date   
    date_filed_max = "2024-01-01",  # End date
    collapse = ","
)
api_token <- <hidden>
data <- GET(
   "https://www.courtlistener.com/api/rest/v4/dockets/",
    query = query_params,
    add_headers(Authorization = paste("Token", api_token))
)
1
  • Do you know if documentation for this API endpoint exists? Every website is different and unless you know the exact expected syntax, it's hard to know what R code would work. Commented Jan 15 at 18:18

1 Answer 1

1

According to the documentation, under Filtering, you can filter your parameters by appending a specific option using double underscores. Since you're wanting to filter based on date_filed, the documentation says we can pass an OPTIONS request on the API endpoint and inspect the filters key in the response. In httr, this might look something like:

library(httr)

dockets <- "https://www.courtlistener.com/api/rest/v4/dockets/"

# Allows us to pass any arbitrary verb besides the usual suspects (e.g., GET, POST, etc.)
filter_options <- httr::VERB(
  verb = "OPTIONS",
  url = dockets
) |>
  content() |>
  purrr::pluck("filters", "date_filed", "lookup_types")|> 
  purrr::list_simplify()
# Print our options out
filter_options
[1] "exact" "gte"   "gt"    "lte"   "lt"    "range" "year"  "month" "day" 

So we can see that the options available to us include exact filtering, greater than or equal to (gte), greater than (gt), less than or equal to (lte), less than (lt), range, year, month and day. Range seems to best fit our purposes, so then our query parameters would instead look something like:

query_params <- list(
  q = "defamation OR libel OR slander",  # Search for relevant cases   
  date_filed__range = "2023-01-01,2024-01-01"
)

From here, we perform the request as before and the result returns only those docket items filed between January 1, 2023 and January 1, 2024:

data <- GET(url = dockets, query = query_params) |>
  content() |>
  purrr::pluck("results")

Hope that helps! Edit: I omitted the API key in the requests since I do not have one and Court Listener allows you to request data without one, but in your use case, if you want to avoid running into issues from throttling or rate-limiting, it's best to include your API key in the requests.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.