Skip to main content
Use cuey.repeat() as a convenient alias for cuey.crons.create(). Both methods are equivalent.

Overview

Create a new cron job that will execute according to the specified cron expression.
import { cuey } from "cuey";

const cron = await cuey.crons.create({
  webhook_url: "https://api.example.com/webhook",
  cron_expression: "0 9 * * *", // Daily at 9 AM
  timezone: "America/New_York",
  payload: {
    report_type: "daily",
  },
});

Parameters

webhook_url
string
required
The full URL of the webhook endpoint to call. Must be a valid HTTP/HTTPS URL.
method
string
default:"POST"
HTTP method to use for the webhook request. Options: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS. Defaults to POST.
cron_expression
string
required
Cron expression defining the schedule (e.g., 0 9 * * * for daily at 9 AM). See the Cron Expressions guide for more information.
timezone
string | null
Timezone for the cron schedule (e.g., America/New_York). null or omit for UTC.
headers
object | null
Custom headers to include in the webhook request. Object with string keys and values.
payload
object | null
Payload to send with the webhook request. Can be any JSON-serializable object.
retry_config
object | null
Retry configuration for failed webhook attempts.
is_active
boolean
default:"true"
Whether the cron job should be active immediately. Defaults to true. Set to false to create an inactive cron that won’t execute until activated.

Response

cron
Cron
required
The created cron job object.
{
  "id": "cron-uuid-here",
  "cron_expression": "0 9 * * *",
  "timezone": "America/New_York",
  "webhook_url": "https://api.example.com/webhook",
  "method": "POST",
  "headers": {
    "Authorization": "Bearer token"
  },
  "payload": {
    "report_type": "daily"
  },
  "retry_config": {
    "maxRetries": 5,
    "backoffMs": 2000,
    "backoffType": "exponential"
  },
  "is_active": true,
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z",
  "team_id": "team-uuid-here"
}

Errors

  • ValidationError: If cron expression is invalid or webhook URL is invalid
  • UnauthorizedError: If API key is invalid or missing

Examples

Common Cron Expressions

import { cuey } from "cuey";

// Every minute
await cuey.crons.create({
  webhook_url: "https://api.example.com/webhook",
  cron_expression: "* * * * *",
});

// Every hour
await cuey.crons.create({
  webhook_url: "https://api.example.com/webhook",
  cron_expression: "0 * * * *",
});

// Daily at midnight
await cuey.crons.create({
  webhook_url: "https://api.example.com/webhook",
  cron_expression: "0 0 * * *",
});

// Every Monday at 9 AM
await cuey.crons.create({
  webhook_url: "https://api.example.com/webhook",
  cron_expression: "0 9 * * 1",
  timezone: "America/New_York",
});

Create Multiple Cron Jobs

import { cuey } from "cuey";

// Hourly health check
const hourlyCheck = await cuey.crons.create({
  webhook_url: "https://api.example.com/health-check",
  cron_expression: "0 * * * *",
  payload: { check_type: "health" },
});

// Daily backup
const dailyBackup = await cuey.crons.create({
  webhook_url: "https://api.example.com/backup",
  cron_expression: "0 2 * * *", // 2 AM daily
  timezone: "UTC",
  payload: { backup_type: "full" },
});

// Weekly report
const weeklyReport = await cuey.crons.create({
  webhook_url: "https://api.example.com/report",
  cron_expression: "0 9 * * 1", // Monday at 9 AM
  timezone: "America/New_York",
  payload: { report_type: "weekly" },
});