---
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/vi/api-reference/senders/routes/run-commands

Người gửi: tuyến

# Run Commands

Điểm truy cập duy nhất cho người gửi. Gửi 1 đến 20 lệnh trong một yêu cầu và nhận một kết quả cho mỗi lệnh.

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

Cùng cấu trúc như Domains, Contacts và Logs. Các trang bên dưới mô tả từng lệnh.

Lỗi được báo theo từng lệnh. Một lệnh lỗi không dừng các lệnh khác, và trạng thái HTTP vẫn là `200`.

## Tham số body

- `commands` object[] bắt buộc
1 đến 20 lệnh, chạy theo thứ tự. Toàn bộ body tối đa 1 MB.
- `commands[].command` string bắt buộc
`list_senders`, `get_sender`, `create_sender`, `update_sender`, `update_sender_description` hoặc `delete_sender`.
- `commands[].args` object không bắt buộc
Tham số của lệnh. Bất kỳ giá trị nào cũng có thể là `$ref` tới kết quả của lệnh trước.
- `commands[].id` string không bắt buộc
Mã định danh riêng cho kết quả. Mặc định là chỉ số (`"0"`, `"1"`…). Bắt buộc nếu muốn dùng `$ref`.

## Bắt đầu nhanh

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/sender',
  {
    commands: [
      {
        command: "list_senders",
        id: "all"
      },
      {
        command: "get_sender",
        id: "one",
        args: {
          sender_id: "K7Q2M9XR4TB8WD1ZC6NF3HJP"
        }
      }
    ]
  },
  { 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);
}
```

## Phản hồi

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "list_senders",
      "id": "all",
      "type": "SUCCESS",
      "took_ms": 5,
      "data": {
        "senders": [
          {
            "sender_id": "K7Q2M9XR4TB8WD1ZC6NF3HJP",
            "email": "hello@acme.com",
            "username": "hello",
            "domain": "acme.com",
            "from_name": "Acme",
            "reply_to": "support@acme.com",
            "description": "Product updates",
            "avatar_color": "#2F6FDB",
            "warmup_enabled": false,
            "reputation": {
              "delivered": 18420,
              "bounced": 131,
              "spam": 6,
              "received_messages": 2210,
              "total_emails": 18557,
              "has_minimum_volume": true,
              "delivery_rate": 99,
              "bounce_rate": 1,
              "spam_rate": 0,
              "engagement_rate": 12,
              "score": 100,
              "status": "Excellent"
            },
            "created_at": "2026-09-02T14:40:12.530Z",
            "updated_at": "2026-10-20T08:15:33.004Z"
          }
        ]
      }
    },
    {
      "command": "get_sender",
      "id": "one",
      "type": "SUCCESS",
      "took_ms": 2,
      "data": {
        "sender_id": "K7Q2M9XR4TB8WD1ZC6NF3HJP",
        "email": "hello@acme.com",
        "username": "hello",
        "domain": "acme.com",
        "from_name": "Acme",
        "reply_to": "support@acme.com",
        "description": "Product updates",
        "avatar_color": "#2F6FDB",
        "warmup_enabled": false,
        "reputation": {
          "delivered": 18420,
          "bounced": 131,
          "spam": 6,
          "received_messages": 2210,
          "total_emails": 18557,
          "has_minimum_volume": true,
          "delivery_rate": 99,
          "bounce_rate": 1,
          "spam_rate": 0,
          "engagement_rate": 12,
          "score": 100,
          "status": "Excellent"
        },
        "created_at": "2026-09-02T14:40:12.530Z",
        "updated_at": "2026-10-20T08:15:33.004Z"
      }
    }
  ]
}
```

### Trường phản hồi

- `type`
Luôn là `SUCCESS` khi bản thân yêu cầu được chấp nhận.
- `results[].command`
Lệnh tạo ra kết quả này.
- `results[].id`
`id` bạn đã gửi, hoặc chỉ số của lệnh.
- `results[].type`
`SUCCESS` hoặc `ERROR`.
- `results[].took_ms`
Thời gian lệnh chạy trong máy chủ.
- `results[].data`
Đầu ra của lệnh. Chỉ có khi `type` là `SUCCESS`.
- `results[].code / message`
Lỗi. Chỉ có khi `type` là `ERROR`.

## Xác thực

Dùng API key bạn tạo trong dashboard, mục Developers → API Keys, với các phạm vi lệnh cần.

- `Authorization`
Gửi `Authorization: <api key>` hoặc `Authorization: Bearer <api key>`.
- `sender:read`
`list_senders` và `get_sender`.
- `sender:create`
`create_sender`.
- `sender:update`
`update_sender` và `update_sender_description`.
- `sender:delete`
`delete_sender`.
- `Token hộp thư`
Token webmail không dùng được ở đây. Nó bị từ chối với `WRONG_CREDENTIAL_TYPE`.
- `IP được phép`
Nếu key có danh sách IP cho phép, yêu cầu từ IP khác nhận `403 IP_NOT_ALLOWED`.

## Nối lệnh với $ref

Tạo người gửi và chuyển id của nó cho lệnh tiếp theo trong cùng yêu cầu.

create_sender → update_sender_description

```
{
  "commands": [
    {
      "command": "create_sender",
      "id": "new",
      "args": {
        "username": "news",
        "from_name": "Acme News",
        "reply_to": "news@acme.com",
        "domain": "acme.com"
      }
    },
    {
      "command": "update_sender_description",
      "args": {
        "sender_id": {
          "$ref": "new",
          "path": "sender_id"
        },
        "description": "Monthly newsletter"
      }
    }
  ]
}
```

## Giới hạn tốc độ

- `15 yêu cầu / giây`
Theo IP + API key. Vượt quá sẽ nhận HTTP 429 với header `Retry-After`.
- `15 đồng thời`
Tối đa 15 yêu cầu được xử lý cùng lúc, theo IP + API key.
- `Theo lệnh, theo tài khoản`
`create_sender` và `update_sender` 10/phút · `update_sender_description` 20/phút · `delete_sender` 30/phút. Vượt quá, lệnh đó trả về `RATE_LIMITED`.
- `Không cache`
Mọi lần gọi đều đọc cơ sở dữ liệu. Kết quả luôn là mới nhất.

## Lỗi

Lỗi ở mức HTTP trả về `type`, `code` và `message`. Lỗi đánh dấu CMD được trả về trong kết quả lệnh, với HTTP 200.

- 400`INVALID_JSON`
Body không phải {"commands":[...]} hoặc lớn hơn 1 MB.
- 400`INVALID_ARGS`
Yêu cầu không có lệnh nào hoặc có hơn 20 lệnh.
- 401`MISSING_AUTH_HEADER`
Không gửi header Authorization.
- 401`INVALID_API_KEY`
API key không tồn tại, đã bị thu hồi hoặc bị tắt trong dashboard.
- 401`API_KEY_EXPIRED`
API key đã quá ngày hết hạn đặt trong dashboard.
- 401`WRONG_CREDENTIAL_TYPE`
Đã gửi token hộp thư. Senders API cần API key từ dashboard.
- 403`IP_NOT_ALLOWED`
Yêu cầu đến từ IP không nằm trong danh sách IP được phép của key.
- 403`ACCOUNT_BLOCKED`
Tài khoản bị khóa.
- 403`MISSING_SCOPE`
Key không có phạm vi `sender:*`, nên không lệnh nào chạy được.
- 429`RATE_LIMITED`
Hơn 15 yêu cầu/giây hoặc 15 yêu cầu đồng thời cho cùng IP + API key. Chờ số giây trong Retry-After.
- 503`AUTH_UNAVAILABLE`
Xác thực tạm thời không khả dụng. Hãy thử lại.
- CMD`UNKNOWN_COMMAND`
Tên lệnh không tồn tại.
- CMD`INTERNAL`
Lỗi máy chủ. Chi tiết chỉ được ghi vào log máy chủ.
