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

# 保持フラグ設定

> 長期保持フラグの設定／解除。

**`PUT`** `https://api-datahub.octoparse.com/v1/datasets/{dataset_id}/retention`

認証：APIキー必須（`Authorization: Bearer <API Key>`）。

実行結果は作成から既定 90 日保持。保持フラグ付きデータセットは期限クリーンアップ対象外。フラグは明示的ユーザー宣言。読み取りでは延長されず、設定／解除は冪等。

自分のデータセットのみマーク可。他人・公開シード・存在しない id は `404`。シードは自分の出力ではなく掃除対象でもないためマーク無意味。マークゲートは可視性より狭い。

## リクエスト

### パスパラメータ

<ParamField path="dataset_id" type="string" required>
  データセット id。
</ParamField>

### リクエスト body

<ParamField body="retained" type="boolean" required>
  保持 `true`、解除 `false`。
</ParamField>

### リクエスト例

```bash theme={null}
curl -X PUT   -H "Authorization: Bearer $OCTOPARSE_API_KEY"   -H "Content-Type: application/json"   -d '{"retained": true}'   "https://api-datahub.octoparse.com/v1/datasets/ds_0bd5345d13d0/retention"
```

## レスポンス

### 200 成功

```json theme={null}
{
  "data": {
    "dataset_id": "ds_0bd5345d13d0",
    "retained": true
  }
}
```

### エラー

| HTTP | `code`              | `category`  | Description                            |
| ---- | ------------------- | ----------- | -------------------------------------- |
| 401  | `unauthorized`      | `forbidden` | API キー欠落または無効。                         |
| 404  | `dataset-not-found` | `not_found` | データセットが存在しない、自分のものでない、または公開シード（マーク不可）。 |

エラー応答は `{"error": {code, category, message, retryable}}` です。<a href="/docs/jp/datahub/api/reference/introduction#errors">エラー</a> を参照。

## クライアントライブラリ

<CodeGroup>
  ```python Python theme={null}
  client.set_dataset_retention("ds_0bd5345d13d0", retained=True)
  ```

  ```js JavaScript theme={null}
  await client.setDatasetRetention("ds_0bd5345d13d0", true);
  ```
</CodeGroup>
