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

# スケジュールを更新する

> Forward Schedule を更新します。

`POST /api/v1/forward/schedules/{schedule_id}`

merge-patch セマンティクスを使用します。リクエストに含まれるフィールドは更新され、省略されたフィールドは変更されません。

## Headers

| Header            | Required | Description            |
| ----------------- | -------- | ---------------------- |
| `Authorization`   | Yes      | `Bearer <PAT>`         |
| `Content-Type`    | Yes      | `application/json`     |
| `Idempotency-Key` | No       | 安全でないリクエスト向けの任意のべき等キー。 |

## Path parameters

| Parameter     | Type   | Required | Description          |
| ------------- | ------ | -------- | -------------------- |
| `schedule_id` | string | Yes      | Forward Schedule ID。 |

## Body parameters

| Parameter        | Type         | Required | Description                            |
| ---------------- | ------------ | -------- | -------------------------------------- |
| `name`           | string       | No       | 新しい Schedule 名。                        |
| `description`    | string       | No       | 新しい Schedule の説明。                      |
| `template_id`    | string       | No       | 新しい Forward Template ID。               |
| `initial_events` | array        | No       | 初期イベントリストを置き換えます。                      |
| `execution`      | object       | No       | 実行ポリシーをマージ更新します。                       |
| `trigger_policy` | object\|null | No       | トリガーポリシーを更新します。`null` は manual に変更します。 |
| `environment_id` | string       | No       | 新しい実行環境。                               |
| `metadata`       | object       | No       | メタデータをマージ更新します。`null` 値はメタデータキーを削除します。 |

## Trigger policy

`trigger_policy` は型付きオブジェクトです。作成および更新リクエストでは、設定フィールドである `type`、`expression`、`timezone` のみを受け付けます。`null` を渡すと Schedule は `{"type":"manual"}` に変更されます。`upcoming_runs_at` と `last_run_at` は Forward が算出するレスポンス専用フィールドです。

| Field              | Type         | Required      | Description                                                                                                      |
| ------------------ | ------------ | ------------- | ---------------------------------------------------------------------------------------------------------------- |
| `type`             | string       | Yes           | `cron`、`once`、`interval`、または `manual`。                                                                           |
| `expression`       | string       | Conditional   | トリガー式。`cron`、`once`、`interval` では必須。`manual` では不要です。                                                             |
| `timezone`         | string       | Conditional   | `Asia/Shanghai` などの IANA タイムゾーン。`cron` では必須。`once` では `expression` にオフセットがない場合のみ必須。`interval` と `manual` では任意です。 |
| `upcoming_runs_at` | array        | Response only | UTC ISO 8601 形式の今後のトリガー時刻。現在の実装では `[]` または次回の予定時刻のみを返します。                                                        |
| `last_run_at`      | string\|null | Response only | 直近のトリガー時刻。                                                                                                       |

| `type`     | Required input                            | Description                                           |
| ---------- | ----------------------------------------- | ----------------------------------------------------- |
| `cron`     | `type`, `expression`, `timezone`          | 指定した IANA タイムゾーンで 5 フィールドの cron 式に従って繰り返します。          |
| `once`     | `type`, `expression`, optional `timezone` | ISO 8601 時刻に 1 回実行します。式にオフセットがない場合は `timezone` が必須です。 |
| `interval` | `type`, `expression`                      | `PT15M` などの ISO 8601 期間に従って繰り返します。                    |
| `manual`   | `type`                                    | 自動的には実行されません。Run Schedule エンドポイントでトリガーします。            |

| `type`     | `expression` format | Example                                          | Notes                                          |
| ---------- | ------------------- | ------------------------------------------------ | ---------------------------------------------- |
| `cron`     | 標準の 5 フィールド cron    | `0 9 * * *`                                      | 分単位のカレンダースケジュール。秒および 6 フィールドの cron はサポートされません。 |
| `once`     | ISO 8601 絶対時刻       | `2026-06-23T09:00:00` または `2026-06-23T01:00:00Z` | 1 回実行します。対象時刻は少なくとも 1 分先である必要があります。            |
| `interval` | ISO 8601 期間         | `PT15M`、`PT1H`、`P1D`                             | 固定間隔スケジュール。最小間隔は 1 分です。                        |
| `manual`   | 省略または空              | -                                                | スケジュール実行を作成しません。                               |

## Execution policy

`execution` はマージ更新されます。省略されたフィールドは現在の値を保持します。

| Field                 | Type    | Default       | Description                           |
| --------------------- | ------- | ------------- | ------------------------------------- |
| `session_mode`        | string  | `new_session` | `new_session` または `reuse_session`。    |
| `max_concurrent_runs` | integer | 1             | この Schedule の最大同時実行数。                 |
| `max_attempts`        | integer | 1             | 予約済み。現在の実装では記録および検証されますが、実行は 1 回のみです。 |
| `timeout_ms`          | integer | 300000        | 1 回の試行のタイムアウト。                        |

| `session_mode`  | Description                                                                                           |
| --------------- | ----------------------------------------------------------------------------------------------------- |
| `new_session`   | トリガーごとに新しい実行 Session を作成します。以前のコンテキストは再利用されません。                                                       |
| `reuse_session` | Forward がこの Schedule 用に固定された 1 つの実行 Session を管理し、トリガー間で再利用します。呼び出し側が任意の既存 `session_id` を指定することはできません。 |

## Example request

```bash theme={null}
curl -s -X POST 'https://api.qoder.com/api/v1/forward/schedules/sched_019f00112233445566778899aabbccdd' \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Weekday tech brief",
    "trigger_policy": {
      "type": "cron",
      "expression": "0 9 * * 1-5",
      "timezone": "Asia/Shanghai"
    }
  }'
```

## Example response

**HTTP 200 OK**

```json theme={null}
{
  "id": "sched_019f00112233445566778899aabbccdd",
  "identity_id": "idn_019eabc123",
  "template_id": "tmpl_support",
  "name": "Weekday tech brief",
  "description": "Generate a daily technology news summary",
  "status": "active",
  "paused_reason": null,
  "initial_events": [
    {
      "type": "user.message",
      "content": "Summarize current technology news in five bullet points."
    }
  ],
  "execution": {
    "session_mode": "new_session",
    "max_concurrent_runs": 1,
    "max_attempts": 1,
    "timeout_ms": 300000
  },
  "trigger_policy": {
    "type": "cron",
    "expression": "0 9 * * 1-5",
    "timezone": "Asia/Shanghai",
    "upcoming_runs_at": ["2026-06-23T01:00:00Z"]
  },
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
  "sinks": [],
  "metadata": {},
  "archived_at": null,
  "created_at": "2026-06-22T10:00:00Z",
  "updated_at": "2026-06-22T10:30:00Z"
}
```

## Response fields

更新された Schedule オブジェクトを返します。

## Errors

| HTTP | Type                    | Code                      | Trigger                     |
| ---- | ----------------------- | ------------------------- | --------------------------- |
| 400  | `invalid_request_error` | `invalid_trigger_policy`  | トリガーポリシーが無効です。              |
| 400  | `invalid_request_error` | `unsupported_sinks_input` | リクエストボディに `sinks` が含まれています。 |
| 404  | `not_found_error`       | `schedule_not_found`      | Schedule が存在しません。           |
| 409  | `invalid_request_error` | `schedule_archived`       | Schedule はアーカイブ済みです。        |

## Notes

* HTTP 更新リクエストは `sinks` の更新をサポートしません。
* `reuse_session` は Forward がこの Schedule 用に固定された実行 Session を管理することを意味します。呼び出し側が任意の既存 `session_id` を指定することはできません。

## Related

<CardGroup cols={2}>
  <Card title="スケジュールを取得する" icon="file-lines" href="/cloud-agents/api/forward/schedules/get" />

  <Card title="スケジュールを一時停止する" icon="pause" href="/cloud-agents/api/forward/schedules/pause" />
</CardGroup>
