---
title: "Create or update scheduled task"
method: POST
path: "/api/optimize/{catalog}/{namespace}/{table}/schedule"
tags: ["Optimization"]
---

# Create or update scheduled task

`POST /api/optimize/{catalog}/{namespace}/{table}/schedule`

Creates a new scheduled task or updates an existing one for table optimization

## Path parameters

- `catalog` string, required
- `namespace` string, required
- `table` string, required

## Request body

- ScheduledTaskCreate
  - `taskName` string — Name of the scheduled task
  - `cronExpression` string, required — Cron expression for scheduling
  - `enabled` boolean — Whether the task is enabled
  - `snapshotRetention` boolean — Enable snapshot retention cleanup
  - `retentionPeriod` integer — Retention period in milliseconds
  - `minSnapshotsToKeep` integer — Minimum number of snapshots to keep
  - `orphanFileDeletion` boolean — Enable orphan file deletion
  - `orphanFileRetention` integer — Orphan file retention period in milliseconds
  - `compaction` boolean — Enable table compaction
  - `targetFileSizeBytes` integer — Target file size for compaction in bytes
  - `strategy` string — Compaction strategy (e.g., binpack, sort)
  - `sortOrder` string — Sort order for compaction
  - `whereClause` string — WHERE clause to filter data during compaction
  - `createdBy` string — User who created the task

## Response `200`

Scheduled task created/updated successfully

- ScheduledTaskResponse
  - `success` boolean, required
  - `message` string, required
  - `taskId` integer
  - `taskName` string
  - `cronExpression` string
  - `cronDescription` string
  - `enabled` boolean
  - `created` boolean — Whether this was a create operation
  - `updated` boolean — Whether this was an update operation

## Other responses

- `400` — Invalid request parameters
- `500` — Internal server error

---

[API](https://skmtc.dev/nimtable/apis/nimtable-api.md) · [All operations](https://skmtc.dev/nimtable/apis/nimtable-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/nimtable/nimtable-api/revisions/b8d40ad56ee0/schema)
