Skip to content

Instantly share code, notes, and snippets.

@emasters
Last active November 2, 2018 18:32
Show Gist options
  • Save emasters/f69675b330934ded7441c8c32f1749fa to your computer and use it in GitHub Desktop.
Save emasters/f69675b330934ded7441c8c32f1749fa to your computer and use it in GitHub Desktop.
First swipe at using the CAP API to retreive a the full text of a case.
<?php
/**
* Working with Harvard's CAP API
*
*/
$authorization = "Token your-API-key-here";
$cite = "309 F.2d 912";
$full_case = "true";
$body_format = "html";
$params = array(
'cite' => $cite,
'full_case' => $full_case,
'body_format' => $body_format,
);
$query = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.case.law/v1/cases/?$query");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: '.$authorization,
)
);
$result = curl_exec($ch);
curl_close($ch);
//echo "<pre>".$result."</pre><hr>";
$capresult = (json_decode($result,true));
//print("<pre>".print_r($capresult,true)."</pre>");
echo $capresult['results'][0]['casebody']['data'];
?>
@emasters
Copy link
Author

emasters commented Nov 1, 2018

To get a n API key you'll need to create an account on case.law and then visit https://case.law/user/details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment