> ## 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 một tin

> Gửi một tin ZNS.

Trả 202 khi tin vào hàng đợi. Mã này xác nhận tiếp nhận, không xác nhận đã giao tới người nhận.

Scope: `messages:send`



## OpenAPI

````yaml https://business.adflex.vn/openapi.json post /api/v1/messages/send
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/send:
    post:
      tags:
        - Gửi tin
      summary: Gửi một tin
      description: >-
        Gửi một tin ZNS.


        Trả 202 khi tin vào hàng đợi. Mã này xác nhận tiếp nhận, không xác nhận
        đã giao tới người nhận.


        Scope: `messages:send`
      operationId: sendMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - template_id
                - phone
              properties:
                template_id:
                  type: string
                  example: '123456'
                  description: Mã template phía Zalo
                phone:
                  type: string
                  example: '84912345678'
                  description: >-
                    Số người nhận. Chấp nhận 0912345678, +84912345678, 912345678
                    — hệ thống tự quy về 84xxxxxxxxx.


                    **API KHÔNG kiểm tra định dạng.** Số sai vẫn vào hàng đợi
                    rồi mới thất bại ở Zalo. Hãy lọc phía bạn trước.
                template_data:
                  $ref: '#/components/schemas/TemplateData'
                tracking_id:
                  type: string
                  example: otp-login-8842
                  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._-]+$
                send_at:
                  type: string
                  format: date-time
                  example: '2026-09-01T09:00:00+07:00'
                  description: ISO 8601, xa nhất 60 ngày. Thời điểm quá khứ = gửi ngay.
                mode:
                  type: string
                  enum:
                    - plain
                    - hashphone
                  description: Bỏ trống = theo mặc định của OA. RSA dùng endpoint riêng.
      responses:
        '202':
          description: Đã nhận vào hàng đợi
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendAccepted'
        '400':
          description: Body sai, thiếu trường, template chưa duyệt, hoặc ví không đủ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '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
    SendAccepted:
      type: object
      properties:
        msg_id:
          type: string
          example: m_a1b2c3d4e5f6g7h8
        tracking_id:
          type: string
          example: otp-login-8842
          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
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
    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:
    Unauthorized:
      description: Thiếu API key, key sai hoặc đã bị thu hồ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à đủ.

````