---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/ja/api-reference/templates/versions/restore-template-version

テンプレート：バージョン

# テンプレートバージョンの復元

htmlテンプレートを以前のバージョン（html、text、subject）に戻します。復元自体が最新のバージョンになるので、これも取り消せます。

POST `https://g.sendcorex.com/v1/template` command: restore_template_version

API keyに`template:update`スコープが必要です。

1アカウントにつき1分あたり最大20回。超えるとコマンドは`RATE_LIMITED`を返します。

## 引数

- `template_id` string 必須
htmlテンプレート。
例： `"html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93"`
- `version_at` string 必須
List Template Versionsで得た`version_at`をそのまま。
例： `"2026-10-21T04:09:12.004Z"`

## クイックスタート

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/template',
  {
    commands: [
      {
        command: "restore_template_version",
        args: {
          template_id: "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
          version_at: "2026-10-21T04:09:12.004Z"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);
```

## レスポンス

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "restore_template_version",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 11,
      "data": {
        "template_id": "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
        "type": "html",
        "name": "Welcome email",
        "reference": "K7Q2M9XR4T",
        "preview": null,
        "has_html": true,
        "html_size": 248,
        "editable": true,
        "created_at": "2026-10-21T04:02:11.310Z",
        "updated_at": "2026-10-21T04:40:02.118Z",
        "subject": "Welcome to Acme",
        "html": "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
        "text": "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"
      }
    }
  ]
}
```

### レスポンスの項目

- `template_id`
テンプレートのid：`html_<uuid>`、`unlayer_<number>`、`custom_<uuid>`。ほかのすべてのコマンドで使います。
- `type`
`html`（APIで送った自分のもの）、`unlayer`（ドラッグ＆ドロップのエディターで作成）、`custom`（Sendcorexのエディターで作成）。
- `name`
付けた名前。
- `reference`
ダッシュボードでもテンプレートを識別できる短いコード。
- `preview`
エディターのテンプレートの画像。htmlテンプレートと、まだ保存されていないエディターのテンプレートでは`null`。
- `has_html`
作成されたが一度も保存されていないエディターのテンプレートでは`false`。まだレンダリングも送信もできません。
- `html_size`
htmlのサイズ（バイト）。
- `editable`
htmlテンプレートでは`true`：ここで更新、復元、削除ができます。エディターのテンプレートはAPIでは読み取り専用です。
- `created_at / updated_at`
ISO 8601、UTC。
- `subject`
既定の件名、または`null`。変数を含められます。
- `html`
html。一度も保存されていないエディターのテンプレートでは`null`。
- `text`
プレーンテキスト版、または`null`。付けて送ってください：テキスト版のあるメールを好むクライアントやフィルターがあります。

## エラー

HTTPレベルのエラーは`type`、`code`、`message`を返します。CMDと表示されたエラーは、HTTP 200でコマンドの結果内に返ります。

- 401`INVALID_API_KEY`
API keyが存在しないか、取り消されたか、ダッシュボードで無効化されています。
- 429`RATE_LIMITED`
同じIP + API keyで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。
- CMD`MISSING_SCOPE`
API keyにこのコマンドに必要なスコープがありません。
- CMD`INVALID_ARGS`
引数が無効です：形式が正しくない`template_id`、`name`や`html`がない、255文字を超える名前、RFC 3339でない`version_at`…
- CMD`TEMPLATE_NOT_FOUND`
テンプレートがアカウントにありません。
- CMD`TEMPLATE_READ_ONLY`
UnlayerまたはCustomのテンプレートです：ダッシュボードのエディターで編集してください。APIで変更できるのはhtmlテンプレートだけです。
- CMD`VERSION_NOT_FOUND`
そのバージョンは存在しません。保存されるのは直近10件だけです。
- CMD`RATE_LIMITED`
直近1分間にアカウントがこのコマンドを呼びすぎました。1分待ってください。
- CMD`INTERNAL`
サーバーエラー。詳細はサーバーのログにのみ記録されます。
