---
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/receive-emails/audience/save-segment

メールの受信：連絡先とオーディエンス

# Save Segment

このメールボックスのセグメントを作成または更新します。

POST `https://g.sendcorex.com/v1` command: save_segment

セグメントは1つのメールボックスに属します。別のメールボックスで使うには、そこにコピーを保存してください。

整理の権限が必要です（読み取り専用トークンでは使えません）。

## 引数

- `segment_id` string 任意
新しいセグメントを作成する場合は省略します。
- `name` string 必須
200文字まで。
- `where` object 必須
絞り込み。`list_contacts`と同じ形式。
- `sort` object 任意
`{ field }`：`email`、`created_at`、`last_open_at`、`last_click_at`、`open_count`、`click_count`。

## クイックスタート

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "save_segment",
        args: {
          name: "Opened in 30 days",
          where: {
            last_open_at: {
              within_days: 30
            }
          }
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

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

## レスポンス

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "save_segment",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "segment": {
          "segment_id": "seg_8Hq2",
          "name": "Opened in 30 days",
          "where": {
            "last_open_at": {
              "within_days": 30
            }
          },
          "sort": null,
          "created_at": "2026-11-21T10:00:00Z",
          "updated_at": "2026-11-21T10:00:00Z"
        }
      }
    }
  ]
}
```

### レスポンスの項目

- `segment`
保存したセグメント。

## エラー

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

- 401`TOKEN_EXPIRED`
access tokenの有効期限が切れました。Refresh Tokenを呼んでリクエストを繰り返してください。
- 401`INVALID_TOKEN`
トークンの形式が不正、不明、または取り消されています。
- 429`RATE_LIMITED`
同じIP + メールボックスで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。
- CMD`INVALID_ARGS`
必須の引数がないか不正です。
- CMD`NOT_FOUND`
このトークンでは、そのメッセージ、スレッド、フォルダーは存在しません。
- CMD`READ_ONLY_ACCESS`
トークンまたはアプリは読み取り専用アクセスで、コマンドは書き込みを行います。添付ファイルのアップロードルートではHTTP 403です。
- CMD`INTERNAL`
サーバーエラー。詳細はサーバーのログにのみ記録されます。
