Use cuey.schedule() as a convenient alias for cuey.events.create(). Both methods are equivalent.
Overview
Create a new scheduled event that will execute once at the specified time.
import { cuey } from "cuey";
const event = await cuey.events.create({
webhook_url: "https://api.example.com/webhook",
scheduled_at: "2024-12-31T23:59:59Z",
payload: {
message: "Happy New Year from Cuey!",
},
});
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.
ISO 8601 timestamp when the event should execute. Must be in the future.
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.
Response
The created event object.
Unique identifier for the event (UUID).
ISO 8601 timestamp when the event is scheduled to execute.
Initial status will be pending.
The webhook URL that will be called.
HTTP method used for the webhook request.
Custom headers to include in the webhook request.
Payload to send with the webhook request.
Retry configuration for failed webhooks.
{
"id": "event-uuid-here",
"cron_id": null,
"retry_of": null,
"scheduled_at": "2024-12-31T23:59:59Z",
"executed_at": null,
"status": "pending",
"webhook_url": "https://api.example.com/webhook",
"method": "POST",
"headers": {
"Authorization": "Bearer token"
},
"payload": {
"message": "Happy New Year from Cuey!"
},
"retry_config": {
"maxRetries": 3,
"backoffMs": 1000,
"backoffType": "exponential"
},
"response_status": null,
"response_headers": null,
"response_body": null,
"response_duration": null,
"response_error": null,
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"team_id": "team-uuid-here"
}
Errors
The scheduled_at timestamp must be in the future. The SDK validates this client-side before making the API call.
ValidationError: If scheduled_at is in the past or invalid, or if webhook URL is invalid
UnauthorizedError: If API key is invalid or missing
Examples
Schedule Event in One Hour
import { cuey } from "cuey";
const oneHourFromNow = new Date(Date.now() + 60 * 60 * 1000);
const event = await cuey.events.create({
webhook_url: "https://api.example.com/webhook",
scheduled_at: oneHourFromNow.toISOString(),
payload: {
message: "Scheduled for 1 hour from now",
},
});
console.log("Event scheduled:", event.id);
Schedule Multiple Events
import { cuey } from "cuey";
const events = await Promise.all([
cuey.events.create({
webhook_url: "https://api.example.com/webhook",
scheduled_at: new Date(Date.now() + 60000).toISOString(),
payload: { event: "reminder_1" },
}),
cuey.events.create({
webhook_url: "https://api.example.com/webhook",
scheduled_at: new Date(Date.now() + 120000).toISOString(),
payload: { event: "reminder_2" },
}),
]);
console.log(`Scheduled ${events.length} events`);