client.gear manages bikes, shoes and other equipment, including maintenance reminders and per-item distance and time totals. Routes are athlete-scoped.
| Method | What it does |
|---|---|
| GearService.create | Create a new gear item |
| GearService.update | Update a gear item |
| GearService.delete | Delete a gear item |
| GearService.replace | Replace a gear item (transfer activities to a new gear item) |
| GearService.createReminder | Create a gear reminder |
| GearService.updateReminder | Update a gear reminder |
| GearService.deleteReminder | Delete a gear reminder |
| GearService.list | All of the athlete's gear |
| GearService.downloadCSV | All of the athlete's gear as CSV |
| GearService.calc | Recalculate distance / time / activity totals for one item of gear |
List the athlete's gear, recalculate totals for the first item, then download all gear as CSV.
const client = new IntervalsClient({ apiKey });
const gear = await client.gear.list();
console.log(`${gear.length} items of gear`);
for (const item of gear) {
console.log(`- ${item.name ?? item.id} (${item.type ?? 'unknown type'}): ${item.distance ?? 0} m`);
}
const first = gear[0];
if (!first || first.id === undefined) {
console.log('No gear found');
} else {
const stats = await client.gear.calc(first.id);
console.log(`Totals for ${first.name ?? first.id}: distance=${stats.distance ?? 0} activities=${stats.activities ?? 0}`);
}
const csv = await client.gear.downloadCSV();
console.log(`Gear CSV: ${csv.length} bytes`);
Create a maintenance reminder on the athlete's first gear item, then delete it.
CI never runs this example; running it by hand changes the authenticated account. If the create call itself fails after the server committed it, nothing is cleaned up: search the account for Created by the SDK example (or Uploaded by the SDK example) and delete it by hand.
// maxRetries: 0 — a create that committed before a 5xx would be repeated by a retry, and only the last response's id would be cleaned up.
const client = new IntervalsClient({ apiKey, maxRetries: 0 });
const gear = await client.gear.list();
const item = gear[0];
if (!item || item.id === undefined) {
console.log('No gear found; add an item of gear before running this example');
} else {
console.log(`Using gear: ${item.name ?? item.id}`);
// A unique marker in the message: if the create fails after the server committed it,
// this is what to search the account for.
const marker = `Created by the SDK example ${Date.now()}`;
const reminder = await client.gear.createReminder(item.id, {
type: 'DISTANCE',
threshold: 5000,
message: marker,
});
if (typeof reminder.id !== 'number') {
console.error('The API did not return an id for the created reminder; it may need deleting by hand.');
process.exit(1);
}
const reminderId = reminder.id;
console.log(`Created reminder id=${reminderId}`);
try {
console.log(`Reminder message: ${reminder.message}`);
} finally {
await client.gear.deleteReminder(item.id, reminderId);
console.log(`Deleted reminder ${reminderId}`);
}
}