---
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/contacts/actions/add-tags

連絡先：タグ、ステータス、項目

# タグの追加

最大500件の連絡先に1つ以上のタグを追加します。タグはその場で作成され、大文字小文字やアクセントは区別しません。

POST `https://g.sendcorex.com/v1/contacts` command: add_tags

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

## 引数

- `emails` string[] 任意
最大500件のメールアドレス。大文字小文字と前後の空白は無視され、重複は1件として数えます。
- `email` string 任意
単一のメールアドレス。これか`emails`を使います。
- `tags` string[] 必須
追加するタグ。`"Black Friday"`と`"black friday"`は同じタグです。
例： `["black-friday"]`
- `return_contacts` boolean 任意
各要素に変更後の連絡先全体を追加します。

## クイックスタート

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "add_tags",
        args: {
          emails: [
            "ana@acme.com",
            "bob@gmail.com"
          ],
          tags: [
            "black-friday"
          ]
        }
      }
    ]
  },
  { 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": "add_tags",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "items": [
          {
            "id": "ana@acme.com",
            "ok": true,
            "data": {
              "changed": true
            }
          },
          {
            "id": "bob@gmail.com",
            "ok": true,
            "data": {
              "changed": true
            }
          }
        ],
        "ok_count": 2,
        "failed_count": 0
      }
    }
  ]
}
```

### レスポンスの項目

- `items[].id`
送ったメールアドレス（送ったとおりの形）。
- `items[].ok`
このメールアドレスが成功した場合は`true`。`false`の場合、要素に`code`と`message`が含まれます。
- `items[].data.changed`
`false`は連絡先がすでにその状態だったため、何も書き込まれなかったことを意味します。
- `items[].data.contact`
変更後の連絡先全体。`return_contacts: true`の場合のみ。
- `ok_count / failed_count`
成功したメールアドレスと失敗したメールアドレスの数。

## クエリで見つかった全員にタグ付け

Query Contactsと`$ref`を組み合わせると、メールをアプリに通さずに1回のリクエストでセグメント全体にタグ付けできます。

リクエストボディ

```
{
  "commands": [
    {
      "command": "query_contacts",
      "id": "q",
      "args": {
        "where": {
          "last_open_at": {
            "within_days": 7
          }
        },
        "select": [
          "email"
        ],
        "limit": 500
      }
    },
    {
      "command": "add_tags",
      "args": {
        "emails": {
          "$ref": "q",
          "path": "contacts/*/email"
        },
        "tags": [
          "active-this-week"
        ]
      }
    }
  ]
}
```

1つの連絡先に付けられるタグは最大50件。アカウントごとのタグ数はGet Statsで確認できます。

## エラー

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`
必須の引数がないか不正です：メールアドレス、項目の値、enumの選択肢、whereのキー、リストのid…
- CMD`NOT_FOUND`
連絡先、リスト、項目、またはセグメントが存在しません。
- CMD`INTERNAL`
サーバーエラー。詳細はサーバーのログにのみ記録されます。
