Skip to main content
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

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.
scheduled_at
string
required
ISO 8601 timestamp when the event should execute. Must be in the future.
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.

Response

event
Event
required
The created event object.
{
  "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`);