> ## Documentation Index
> Fetch the complete documentation index at: https://docs-zns.adflex.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# Gửi lô tối đa 500 tin

> Gửi tối đa 500 tin cùng một template.

Đối chiếu `accepted` với `total`; phần tử có `status: "error"` không được gửi. Số dư được kiểm tra cho toàn lô trước khi xếp hàng: thiếu số dư trả 402 và không tin nào được gửi.

Scope: `messages:send`



## OpenAPI

````yaml https://business.adflex.vn/openapi.json post /api/v1/messages/batch
openapi: 3.1.0
info:
  title: AdFlex ZNS API
  version: 1.0.0
  description: >-
    API gửi tin Zalo ZNS của AdFlex.


    API vận hành ở chế độ production, không có môi trường sandbox. Mỗi request
    thành công tạo một tin thật và trừ phí theo giá template.
  contact:
    name: AdFlex for Business
    url: https://business.adflex.vn
servers:
  - url: https://business.adflex.vn
    description: Production
security:
  - bearerAuth: []
  - apiKeyAuth: []
tags:
  - name: Template
    description: Khám phá template và OA khả dụng
  - name: Gửi tin
    description: Gửi một tin, gửi lô, gửi mã hoá đầu-cuối
  - name: Tra cứu
    description: Trạng thái tin và huỷ tin chưa gửi
paths:
  /api/v1/messages/batch:
    post:
      tags:
        - Gửi tin
      summary: Gửi lô tối đa 500 tin
      description: >-
        Gửi tối đa 500 tin cùng một template.


        Đối chiếu `accepted` với `total`; phần tử có `status: "error"` không
        được gửi. Số dư được kiểm tra cho toàn lô trước khi xếp hàng: thiếu số
        dư trả 402 và không tin nào được gửi.


        Scope: `messages:send`
      operationId: sendBatch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - template_id
                - recipients
              properties:
                template_id:
                  type: string
                  example: '123456'
                send_at:
                  type: string
                  format: date-time
                  description: Áp cho cả lô
                mode:
                  type: string
                  enum:
                    - plain
                    - hashphone
                  description: Áp cho cả lô
                recipients:
                  type: array
                  minItems: 1
                  maxItems: 500
                  description: >-
                    Tối đa 500 mỗi request. Thực tế nên chia 100–200 cho dễ
                    retry.
                  items:
                    type: object
                    required:
                      - phone
                    properties:
                      phone:
                        type: string
                        example: '84912345678'
                      template_data:
                        $ref: '#/components/schemas/TemplateData'
                      tracking_id:
                        type: string
                        description: >-
                          Mã đối soát do hệ thống của bạn định nghĩa. Không
                          truyền thì AdFlex dùng msg_id.


                          Tối đa 48 ký tự; chỉ chấp nhận chữ, số, dấu chấm, gạch
                          ngang, gạch dưới. Vi phạm trả lỗi 400.
                        maxLength: 48
                        pattern: ^[A-Za-z0-9._-]+$
      responses:
        '202':
          description: Lô đã được nhận — kiểm tra từng phần tử trong results
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchAccepted'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    TemplateData:
      type: object
      description: Khoá là tên tham số lấy từ GET /api/v1/templates, giá trị luôn là chuỗi.
      additionalProperties:
        type: string
      example:
        otp: '246813'
        time: 5 phut
    BatchAccepted:
      type: object
      description: >-
        202 nghĩa là lô đã được nhận, KHÔNG nghĩa là mọi người nhận đều hợp lệ.
        Luôn đọc results.
      properties:
        accepted:
          type: integer
          description: Số người nhận thực sự vào hàng đợi
        total:
          type: integer
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
        results:
          type: array
          items:
            $ref: '#/components/schemas/BatchResult'
    BatchResult:
      type: object
      properties:
        phone:
          type: string
        msg_id:
          type: string
          description: Chỉ có khi status=queued
        tracking_id:
          type: string
          description: >-
            Mã đối soát do hệ thống của bạn định nghĩa. Không truyền thì AdFlex
            dùng msg_id.


            Tối đa 48 ký tự; chỉ chấp nhận chữ, số, dấu chấm, gạch ngang, gạch
            dưới. Vi phạm trả lỗi 400.
          maxLength: 48
          pattern: ^[A-Za-z0-9._-]+$
        status:
          type: string
          enum:
            - queued
            - error
        error:
          type: string
          description: Chỉ có khi status=error
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
              example: 401
            message:
              type: string
              example: API key không hợp lệ hoặc đã bị thu hồi
  responses:
    BadRequest:
      description: Body sai hoặc thiếu trường bắt buộc
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Thiếu API key, key sai hoặc đã bị thu hồi
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    PaymentRequired:
      description: Ví không đủ cho cả lô — không tin nào được gửi
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Key thiếu scope, hoặc workspace đang tạm dừng
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Không tìm thấy tài nguyên trong workspace của key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Authorization: Bearer ak_live_…'
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Cách thay thế cho Bearer. Dùng một trong hai là đủ.

````