Cards and results › Results as they land
Results as they land
The ten most recently settled races your plan can read. Run it every two minutes and you see each result as it lands.
<?php
// Results as they land
const BASE = "https://api.apihorseracing.com";
function get(string $path, array $params = []): array
{
$url = BASE . $path . ($params ? "?" . http_build_query($params) : "");
$ctx = stream_context_create(["http" => [
"header" => "X-API-Key: " . getenv("AHR_KEY"),
"ignore_errors" => true,
]]);
$body = json_decode(file_get_contents($url, false, $ctx), true);
if (isset($body["error"])) {
throw new RuntimeException($body["error"]["code"] . ": " . $body["error"]["message"]);
}
return $body["data"];
}
$data = get("/v1/results/latest", ["limit" => "10"]);
foreach ($data as $row) {
echo $row["date"], " ", $row["time"], " ", $row["course"], " ", $row["name"], "\n";
}
What the reply holds
- date
- The race day.
- time
- The off.
- course
- The course.
- winning_time
- The winning time, where published.
- book_percentage
- The book, as a percentage.
When it says no
401no_key The key is missing or mistyped. Every sample reads it from AHR_KEY.403plan_needed Your plan does not reach this. The reply names the plan that does.429rate_limited Too fast. Wait the seconds in Retry-After, then try again.