> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cuey.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Cron

> Update an existing cron job

## Overview

Update an existing cron job. When you update a cron job, all pending events created by that cron are automatically deleted and new events will be generated based on the updated schedule.

<RequestExample>
  ```typescript Update cron schedule theme={null}
  import { cuey } from "cuey";

  const updatedCron = await cuey.crons.update("cron-id", {
    webhook_url: "https://api.example.com/webhook",
    cron_expression: "*/30 * * * *", // Every 30 minutes
    timezone: "America/New_York",
    is_active: true,
  });
  ```

  ```typescript Temporarily disable cron theme={null}
  import { cuey } from "cuey";

  await cuey.crons.update("cron-id", {
    webhook_url: "https://api.example.com/webhook",
    cron_expression: "0 0 * * *",
    is_active: false, // Disabled
  });
  ```
</RequestExample>

## Parameters

<ParamField path="id" type="string" required>
  The UUID of the cron job to update.
</ParamField>

<ParamField body="webhook_url" type="string" required>
  The full URL of the webhook endpoint to call. Must be a valid HTTP/HTTPS URL.
</ParamField>

<ParamField body="method" type="string">
  HTTP method to use for the webhook request. Options: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`. Defaults to `POST`.
</ParamField>

<ParamField body="cron_expression" type="string" required>
  Cron expression defining the schedule (e.g., `0 9 * * *` for daily at 9 AM).
</ParamField>

<ParamField body="timezone" type="string | null">
  Timezone for the cron schedule (e.g., `America/New_York`). `null` for UTC.
</ParamField>

<ParamField body="headers" type="object | null">
  Custom headers to include in the webhook request. Object with string keys and values.
</ParamField>

<ParamField body="payload" type="object | null">
  Payload to send with the webhook request. Can be any JSON-serializable object.
</ParamField>

<ParamField body="retry_config" type="object | null">
  Retry configuration for failed webhook attempts.

  <Expandable title="RetryConfig properties">
    <ParamField body="maxRetries" type="number" required>
      Maximum number of retry attempts. Range: 1-10.
    </ParamField>

    <ParamField body="backoffMs" type="number" required>
      Initial backoff delay in milliseconds. Range: 100-5000.
    </ParamField>

    <ParamField body="backoffType" type="string" required>
      Backoff strategy. Options: `exponential`, `linear`.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="is_active" type="boolean">
  Whether the cron job should be active. `true` to activate, `false` to deactivate.
</ParamField>

## Response

<ResponseField name="cron" type="Cron" required>
  The updated cron job object.
</ResponseField>

<ResponseExample>
  ```json Success response theme={null}
  {
    "id": "cron-uuid-here",
    "cron_expression": "*/30 * * * *",
    "timezone": "America/New_York",
    "webhook_url": "https://api.example.com/webhook",
    "method": "POST",
    "headers": null,
    "payload": null,
    "retry_config": null,
    "is_active": true,
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-16T12:00:00Z",
    "team_id": "team-uuid-here"
  }
  ```
</ResponseExample>

## Errors

<Note>
  When you update a cron job, all pending events created by that cron are automatically deleted and new events will be generated based on the updated schedule.
</Note>

* `NotFoundError`: If the cron job doesn't exist
* `ValidationError`: If the update data is invalid (e.g., invalid cron expression)
* `UnauthorizedError`: If API key is invalid or missing

## Examples

### Update Cron Schedule

```typescript theme={null}
import { cuey } from "cuey";

const cron = await cuey.crons.get("cron-id");

const updated = await cuey.crons.update(cron.id, {
  webhook_url: cron.webhook_url,
  method: cron.method,
  cron_expression: "*/30 * * * *", // Change to every 30 minutes
  timezone: cron.timezone,
  is_active: cron.is_active,
});

console.log("Cron updated:", updated.id);
```

### Toggle Cron Active Status

```typescript theme={null}
import { cuey } from "cuey";

const cron = await cuey.crons.get("cron-id");

// Temporarily disable
await cuey.crons.update(cron.id, {
  webhook_url: cron.webhook_url,
  method: cron.method,
  cron_expression: cron.cron_expression,
  timezone: cron.timezone,
  is_active: false,
});

// Later, reactivate
await cuey.crons.update(cron.id, {
  webhook_url: cron.webhook_url,
  method: cron.method,
  cron_expression: cron.cron_expression,
  timezone: cron.timezone,
  is_active: true,
});
```
