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
The full URL of the webhook endpoint to call. Must be a valid HTTP/HTTPS URL.
HTTP method to use for the webhook request. Options: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS. Defaults to POST.
Cron expression defining the schedule (e.g., 0 9 * * * for daily at 9 AM). See the Cron Expressions guide for more information.
Timezone for the cron schedule (e.g., America/New_York). null or omit for UTC.
Custom headers to include in the webhook request. Object with string keys and values.
Payload to send with the webhook request. Can be any JSON-serializable object.
Retry configuration for failed webhook attempts.Show RetryConfig properties
Maximum number of retry attempts. Range: 1-10.
Initial backoff delay in milliseconds. Range: 100-5000.
Backoff strategy. Options: exponential, linear.
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
The created cron job object.
Unique identifier for the cron job (UUID).
Cron expression defining the schedule.
Timezone for the cron schedule.
The webhook URL that will be called.
HTTP method used for the webhook request.
Whether the cron job is active.
{
"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" },
});