Create a schedule that runs every 5 minutes

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.create({
  destination: "https://my-api...",
  cron: "*/5 * * * *",
});

Create a schedule that runs every hour and sends the result to a callback URL

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.create({
  destination: "https://my-api...",
  cron: "0 * * * *",
  callback: "https://my-callback...",
  failureCallback: "https://my-failure-callback...",
});

Create a schedule to a URL Group that runs every minute

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.create({
  destination: "my-url-group",
  cron: "* * * * *",
});

Get a schedule by schedule id

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
const res = await schedules.get("scheduleId");
console.log(res.cron);

List all schedules

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
const allSchedules = await schedules.list();
console.log(allSchedules);

Delete a schedule

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.delete("scheduleId");

Create a schedule with timeout

Timeout value in seconds to use when calling a schedule URL (See Upstash-Timeout in Create Schedule page).

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.create({
  url: "https://my-api...",
  cron: "* * * * *",
  timeout: 30 // 30 seconds timeout
});

Pause/Resume a schedule

import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const scheduleId = "my-schedule"

// pause schedule
await client.schedules.pause({ schedule: scheduleId });

// check if paused
const result = await client.schedules.get(scheduleId);
console.log(getResult.isPaused) // prints true

// resume schedule
await client.schedules.resume({ schedule: scheduleId });