Skip to content

Managing Schedules

Create schedules and add team members to on-call rotations.

import { BeepsClient } from "@beepsdev/sdk";
const client = new BeepsClient({
apiKey: process.env.BEEPS_API_KEY,
});
const schedule = await client.schedule.create({
name: "Weekly On-Call",
relayId: "rly_abc123", // Schedule must belong to a relay
type: "weekly", // or "daily"
startDay: "monday", // Day of week for weekly schedules
startTime: "09:00", // Time when rotation occurs (HH:MM format)
externalKey: "prod-oncall", // Optional: custom identifier
});
console.log(`Created schedule: ${schedule.id}`);
const dailySchedule = await client.schedule.create({
name: "Daily On-Call",
relayId: "rly_abc123",
type: "daily",
startDay: "monday", // Not used for daily schedules
startTime: "09:00", // Rotates every day at this time
});
const weeklySchedule = await client.schedule.create({
name: "Weekly On-Call",
relayId: "rly_abc123",
type: "weekly",
startDay: "friday", // Rotates every Friday
startTime: "17:00", // at 5:00 PM
});
const schedules = await client.schedule.list();
console.log(`Found ${schedules.length} schedules:`);
schedules.forEach((schedule) => {
console.log(`- ${schedule.name} (${schedule.type})`);
});

Members are added to the rotation in the order they’re added. The first member is assignment #1, the second is #2, etc.

const member1 = await client.schedule.addMember(schedule.id, {
userId: "usr_alice",
});
console.log(`Added ${member1.userId} to schedule`);
const member2 = await client.schedule.addMember(schedule.id, {
userId: "usr_bob",
});
console.log(`Added ${member2.userId} to schedule`);
const onCall = await client.schedule.getOnCall(schedule.id);
console.log(`Current on-call: ${onCall.email}`);
console.log(`User ID: ${onCall.userId}`);
console.log(`Assignment #: ${onCall.assignmentNumber}`);
const result = await client.schedule.getOnCallSafe(schedule.id);
if (result.error) {
console.error("Failed to get on-call:", result.error.message);
} else {
console.log(`On-call: ${result.data.email}`);
}
type CreateScheduleInput = {
name: string; // Schedule name
relayId: string; // Parent relay ID
type: "daily" | "weekly"; // Rotation frequency
startDay:
| "monday"
| "tuesday"
| "wednesday"
| "thursday"
| "friday"
| "saturday"
| "sunday"; // Day of week (used for weekly schedules)
startTime: string; // Time of day in HH:MM format (24-hour)
externalKey?: string; // Optional custom identifier
};
type Schedule = {
id: string;
organizationId: string;
relayId: string;
name: string;
type: "daily" | "weekly";
startDay:
| "monday"
| "tuesday"
| "wednesday"
| "thursday"
| "friday"
| "saturday"
| "sunday";
startTime: string;
externalKey: string | null;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
};
type AddScheduleMemberInput = {
userId: string; // ID of the user to add to the rotation
};
type ScheduleMember = {
scheduleId: string;
userId: string;
createdAt?: string;
};
type BeepsUser = {
userId: string; // User ID of the person currently on-call
email: string; // Email address
assignmentNumber: number | null; // Current assignment number in rotation (null when schedule has no members)
scheduleId: string; // Schedule ID
isOverride?: boolean; // True if user is on-call via schedule override
overrideId?: string; // ID of the schedule override (if applicable)
};

Always set externalKey for idempotent configuration. All times are in UTC. See Best Practices for details.

const relay = await client.relay.create({
name: "Backend Team Alerts",
});
const schedule = await client.schedule.create({
name: "Backend Weekly Rotation",
relayId: relay.id,
type: "weekly",
startDay: "monday",
startTime: "09:00",
});
const teamMembers = ["usr_alice", "usr_bob", "usr_charlie"];
for (const userId of teamMembers) {
await client.schedule.addMember(schedule.id, { userId });
}
await client.relay.rules.create(relay.id, {
name: "Notify on-call engineer",
ruleType: "schedule_notify",
config: {
scheduleId: schedule.id,
},
});
const onCall = await client.schedule.getOnCall(schedule.id);
console.log(`${onCall.email} is currently on-call`);