Bulk and spreadsheets › Google Sheets
Google Sheets
Yesterday's results straight into a Google Sheet with Apps Script: Extensions, Apps Script, paste, run.
// Google Sheets: Extensions, Apps Script, paste this, set AHR_KEY in
// Project Settings, Script properties, then run fillResults.
function fillResults() {
const key = PropertiesService.getScriptProperties().getProperty("AHR_KEY");
const res = UrlFetchApp.fetch("https://api.apihorseracing.com/v1/results/yesterday?region=GB", {
headers: { "X-API-Key": key },
muteHttpExceptions: true,
});
const body = JSON.parse(res.getContentText());
if (body.error) throw new Error(body.error.code);
const rows = [["Course", "Time", "Race", "Runners"]];
for (const m of body.data) {
for (const race of m.races) rows.push([m.course, race.time, race.name, race.runners]);
}
const sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
}
What the reply holds
- course
- The course.
- races[].time
- The off.
- races[].name
- The race.
- races[].runners
- Runners.
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.