Start here › Find a horse by name
Find a horse by name
Look a horse up by name and get its id, which every horse address takes. Trainers and jockeys work the same way.
# Find a horse by name
import json, os, urllib.parse, urllib.request
BASE = "https://api.apihorseracing.com"
KEY = os.environ["AHR_KEY"]
def get(path, **params):
url = BASE + path + ("?" + urllib.parse.urlencode(params) if params else "")
req = urllib.request.Request(url, headers={"X-API-Key": KEY})
with urllib.request.urlopen(req) as r:
return json.load(r)["data"]
data = get("/v1/horses/search", name="Constitution Hill")
for row in data:
print(row["horse_id"], row["name"])
What the reply holds
- horse_id
- Our id for the horse.
- name
- The name, as raced.
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.