---
title: "Create scheduled task"
method: POST
path: "/api/scheduled-tasks"
tags: ["Scheduled Tasks"]
---

# Create scheduled task

`POST /api/scheduled-tasks`

Creates a new recurring task. Action-target rules:
- `restart` requires `target_type: stack` or `target_type: container` (with `target_id` and `node_id`)
- `auto_stop` and `auto_start` accept `target_type: stack` or `target_type: container`
- `snapshot` requires `target_type: fleet`
- `prune` requires `target_type: system`

Requires admin role.

## Request body

- object
  - `name` string, required
  - `target_type` 'stack' | 'fleet' | 'system' | 'container', required
  - `target_id` string — Stack or container name (required when target_type is `stack` or `container`).
  - `node_id` integer — Target node ID (required when target_type is `stack` or `container`).
  - `action` 'restart' | 'snapshot' | 'prune', required
  - `cron_expression` string, required — Standard 5-field cron expression.
  - `enabled` boolean
  - `prune_targets` string[] — Resources to prune (only for `prune` action).
  - `target_services` string[] — Specific services to restart (only for `restart` action).
  - `prune_label_filter` string — Docker label filter for prune operations.

## Response `201`

Task created.

- ScheduledTask
  - `id` integer, required
  - `name` string, required
  - `target_type` 'stack' | 'fleet' | 'system' | 'container', required
  - `target_id` string, nullable — Stack or container name (when target_type is `stack` or `container`).
  - `node_id` integer, nullable — Target node ID (when target_type is `stack` or `container`).
  - `action` 'restart' | 'snapshot' | 'prune', required
  - `cron_expression` string, required — Standard cron expression (5 fields).
  - `enabled` 0 | 1, required
  - `created_by` string, required
  - `created_at` integer, required — Unix timestamp (seconds).
  - `updated_at` integer, required — Unix timestamp (seconds).
  - `last_run_at` integer, nullable
  - `next_run_at` integer, nullable
  - `last_status` string, nullable
  - `last_error` string, nullable
  - `prune_targets` string, nullable — JSON-stringified array of prune targets (containers, images, networks, volumes).
  - `target_services` string, nullable — JSON-stringified array of service names to restart.
  - `prune_label_filter` string, nullable — Docker label filter for prune operations.

## Other responses

- `400` — Validation error.
- `403` — Insufficient permissions or license tier.
- `500` — Internal server error.

## Changes

- **2026-07-03** `c02adce28613` — 1 warning, 1 info
  - added the new `container` enum value to the `target_type` response property for the response status `201`
  - added the new `container` enum value to the request property `target_type`
- **2026-06-04** `d58cf9d6195b` — 3 info
  - removed the `ADMIRAL_REQUIRED` enum value from the `code` response property for the response status `400`
  - removed the `ADMIRAL_REQUIRED` enum value from the `code` response property for the response status `403`
  - removed the `ADMIRAL_REQUIRED` enum value from the `code` response property for the response status `500`
- **2026-04-05** `7464894ea582` — 3 warning, 3 info
  - added the new `PAID_REQUIRED` enum value to the `code` response property for the response status `400`
  - added the new `PAID_REQUIRED` enum value to the `code` response property for the response status `403`
  - added the new `PAID_REQUIRED` enum value to the `code` response property for the response status `500`
  - removed the `PRO_REQUIRED` enum value from the `code` response property for the response status `400`
  - …2 more
- **2026-04-05** `a202861afa64` — 1 info
  - endpoint added
- **2026-04-03** `82927cbcc9f7` — 1 breaking
  - api path removed without deprecation

[Change history](https://skmtc.dev/studio-saelix/apis/sencho-api/changes/api/scheduled-tasks/post.md)

---

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