puter.events.removeSchedule()Ends a schedule created with puter.events.onSchedule(). It doesn't run again, and it stays in listSchedules() for 7 days with endReason: 'removed'. A run that already started isn't stopped.
It also cancels a notification your app stored to send later with puter.notifications.notify(), the same as puter.notifications.cancel().
The off() method on the schedule onSchedule() returns does the same thing.
On a website with nobody signed in, it asks the user to sign in first, as other Puter.js calls do. An app running on Puter is always signed in.
puter.events.removeSchedule(scheduleId)
scheduleId (String) (required)
The scheduleId from onSchedule(), notify() or listSchedules().
A Promise that resolves when the schedule has ended.
An app can only remove schedules it created. An account session can remove any of the user's schedules, including ones left by apps they no longer use. A scoped access token can't remove any.
An id this caller doesn't hold, or a schedule that already ended, is reported as not existing, so removing a schedule twice rejects the second time. With events_schedule_sending, auth_canceled, too_many_requests or events_disabled, nothing was removed. When the call fails any other way, such as a network error or events_failed, the removal may still have happened, so read the schedule again with getSchedule() to find out.
It rejects with { message, code }:
code |
Meaning |
|---|---|
events_schedule_not_found |
No such schedule, it isn't this caller's, or it already ended. Also for an empty scheduleId. |
events_schedule_sending |
A notification stored to send later has started to go out, so it can't be cancelled. |
auth_canceled |
Nobody was signed in, and the user closed the sign-in without finishing it. |
too_many_requests |
Over the remove rate limit, which is shared with puter.events.unsubscribe(). |
events_disabled |
Schedules aren't available on this server, as on self-hosted servers. |
events_failed |
The server sent a response the SDK couldn't read. |
Cancel a notification, then read it
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
(async () => {
const later = await puter.notifications.notify({
title: 'Your trial ends tomorrow',
sendAt: Date.now() + 24 * 60 * 60 * 1000,
});
if (typeof later !== 'object' || !later) return; // due now, so it was sent at once
await puter.events.removeSchedule(later.scheduleId);
puter.print('cancelled<br>');
// The ended schedule can still be read for 7 days
const ended = await puter.events.getSchedule(later.scheduleId);
puter.print(`${ended.state} (${ended.endReason})<br>`);
})();
</script>
</body>
</html>