---
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/counters/routes/run-commands

カウンター：ルート

# Run Commands

アカウントのカウンターへの唯一の入り口です。1リクエストで1〜20個のコマンドを送り、コマンドごとに1つの結果を受け取ります。

POST `https://g.sendcorex.com/v1/counters`

LogsやContactsと同じエンベロープです。累計、今月、直近30日を1回のリクエストで取得できます。

エラーはコマンドごとに報告されます。1つのコマンドが失敗してもほかは止まらず、HTTPステータスは`200`のままです。

## ボディパラメーター

- `commands` object[] 必須
1〜20個のコマンドを順番に実行します。ボディ全体は1 MBまで。
- `commands[].command` string 必須
`get_totals`、`get_month`、`get_months`、`get_daily`、`get_hourly`のいずれか。
- `commands[].args` object 任意
コマンドの引数。
- `commands[].id` string 任意
結果に付ける独自の識別子。既定はインデックス（`"0"`、`"1"`…）です。

## クイックスタート

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/counters',
  {
    commands: [
      {
        command: "get_totals",
        id: "all"
      },
      {
        command: "get_month",
        id: "now"
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

for (const result of response.data.results) {
  if (result.type !== 'SUCCESS') console.error(result.id, result.code, result.message);
  else console.log(result.id, result.data);
}
```

## レスポンス

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "get_totals",
      "id": "all",
      "type": "SUCCESS",
      "took_ms": 3,
      "data": {
        "totals": {
          "delivered": 48210,
          "bounced": 612,
          "blocked": 88,
          "complaints": 9,
          "rate_limited": 140,
          "total": 49050,
          "delivered_rate": 98.29,
          "bounce_rate": 1.25,
          "blocked_rate": 0.18,
          "complaint_rate": 0.02,
          "rate_limited_rate": 0.29
        }
      }
    },
    {
      "command": "get_month",
      "id": "now",
      "type": "SUCCESS",
      "took_ms": 2,
      "data": {
        "month": "2026-10",
        "delivered": 48210,
        "bounced": 612,
        "blocked": 88,
        "complaints": 9,
        "rate_limited": 140,
        "total": 49050,
        "delivered_rate": 98.29,
        "bounce_rate": 1.25,
        "blocked_rate": 0.18,
        "complaint_rate": 0.02,
        "rate_limited_rate": 0.29
      }
    }
  ]
}
```

### レスポンスの項目

- `type`
リクエスト自体が受け付けられた場合は常に`SUCCESS`。
- `results[].command / id / type`
どのコマンドか、指定したid（またはインデックス）、そして`SUCCESS`または`ERROR`。
- `results[].data`
コマンドの出力。`type`が`SUCCESS`の場合のみ。
- `results[].code / message`
エラー。`type`が`ERROR`の場合のみ。

## 認証

ダッシュボードのDevelopers → API Keysで作成した、scope `counters:read`付きのAPI keyを使ってください。

- `Authorization`
`Authorization: <api key>`または`Authorization: Bearer <api key>`を送ります。
- `counters:read`
このルートに必要な唯一のscopeです。読み取り専用です。
- `メールボックスのトークン`
Webmailのトークンはここでは使えず、`WRONG_CREDENTIAL_TYPE`で拒否されます。

## カウントされるもの

- `すべてのメール`
API、SMTPリレー、キャンペーンをすべてまとめて。各メールは最終結果が出た時点で1回だけカウントされます。
- `リアルタイム`
カウンターは各配信結果の数秒後に更新されます。1日1回のバッチ処理はありません。
- `時間と月はUTC`
`get_hourly`と`get_month(s)`はUTCを使います。`get_daily`は指定したタイムゾーンで日を区切ります。

## レート制限とキャッシュ

- `毎秒15リクエスト`
IP + API keyごと。超えるとHTTP 429と`Retry-After`が返ります。
- `読み取りキャッシュ：1.5秒`
1.5秒以内に同じargsで同じコマンドを送ると、同じ結果が返ります。

## エラー

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

- 400`INVALID_JSON`
ボディが{"commands":[...]}ではないか、1 MBを超えています。
- 400`INVALID_ARGS`
リクエストにコマンドがないか、20個を超えています。
- 401`MISSING_AUTH_HEADER`
Authorizationヘッダーが送られていません。
- 401`INVALID_API_KEY`
API keyが存在しないか、取り消されたか、ダッシュボードで無効化されています。
- 401`API_KEY_EXPIRED`
API keyがダッシュボードで設定した有効期限を過ぎています。
- 401`WRONG_CREDENTIAL_TYPE`
メールボックスのtokenが送られました。Counters APIにはダッシュボードのAPI keyが必要です。
- 403`IP_NOT_ALLOWED`
キーの許可IPにないIPからのリクエストです。
- 403`ACCOUNT_BLOCKED`
アカウントがブロックされています。
- 403`MISSING_SCOPE`
キーに`counters:read`がないため、どのコマンドも実行できません。
- 429`RATE_LIMITED`
同じIP + API keyで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。
- 503`AUTH_UNAVAILABLE`
認証が一時的に利用できません。もう一度お試しください。
- CMD`UNKNOWN_COMMAND`
そのコマンド名は存在しません。
- CMD`INTERNAL`
サーバーエラー。詳細はサーバーのログにのみ記録されます。
